'ヘッダー ウィジェット',
'id' => 'header-widget-area',
'before_widget' => '
',
'before_title' => '',
'after_title' => '
',
]);
register_sidebar([
'name' => 'トップバナー ウィジェット',
'id' => 'topbnr-widget-area',
'before_widget' => '',
'before_title' => '',
'after_title' => '
',
]);
register_sidebar([
'name' => 'トップイメージ ウィジェット',
'id' => 'topimg-widget-area',
'before_widget' => '',
'after_widget' => '
',
'before_title' => '',
'after_title' => '
',
]);
}
add_action('widgets_init', 'cbsonline_widgets_init');
// tweak bogo plugin
// - disable flags
add_filter('bogo_use_flags', 'cbsonline_bogo_use_flags_false');
function cbsonline_bogo_use_flags_false()
{
return false;
}
// - remove ' (United States)' strings from en_US language
add_filter('bogo_language_switcher', 'cbsonline_replace_bogo_text');
function cbsonline_replace_bogo_text($output)
{
return str_replace(' (United States)', '', $output);
}
// add short code
// - topbox : http://www.webopixel.net/wordpress/53.html
function cbsonline_shortcode_TopBox($atts, $content = null)
{
$content = do_shortcode(shortcode_unautop($content));
extract(shortcode_atts(['class' => 'default'], $atts));
return ''.$content.'
';
}
add_shortcode('topbox', 'cbsonline_shortcode_TopBox');
// allow additional image file upload
add_filter('upload_mimes', 'cbsonline_allow_additional_image_upload');
function cbsonline_allow_additional_image_upload($mimes)
{
$mimes['ai'] = 'image/x-illustrator';
$mimes['ico'] = 'image/vnd.microsoft.icon';
return $mimes;
}
// force override Archive widget arguments
add_filter('widget_archives_args', 'cbsonline_widget_archives_args');
function cbsonline_widget_archives_args($args)
{
// yearly
$args['type'] = 'yearly';
// maximum number of items : 10 years
$args['limit'] = 10;
return $args;
}
// support category based archives
add_filter('getarchives_join', 'cbsonline_category_getarchives_join', 10, 2);
function cbsonline_category_getarchives_join($join, $r)
{
global $wpdb;
if (is_category()) {
$cat = intval(get_query_var('cat'));
if ($cat > 0) {
return
" LEFT JOIN $wpdb->term_relationships as r ON $wpdb->posts.ID = r.object_ID
LEFT JOIN $wpdb->term_taxonomy as t ON r.term_taxonomy_id = t.term_taxonomy_id
LEFT JOIN $wpdb->terms as terms ON t.term_id = terms.term_id";
}
}
}
add_filter('getarchives_where', 'cbsonline_category_getarchives_where', 10, 2);
function cbsonline_category_getarchives_where($where, $r)
{
if (is_category()) {
$cat = intval(get_query_var('cat'));
if ($cat > 0) {
return $where." AND t.taxonomy = 'category' AND terms.term_id = $cat";
}
}
}
add_filter('year_link', 'cbsonline_category_year_link', 10, 2);
function cbsonline_category_year_link($url, $year)
{
global $wp_rewrite;
if (is_category()) {
$cat = intval(get_query_var('cat'));
if ($cat > 0) {
$url .= '?cat='.get_query_var('cat');
}
}
return $url;
}
// support tag cloud for static pages
add_action('init', 'cbsonline_add_tag_to_page');
function cbsonline_add_tag_to_page()
{
register_taxonomy_for_object_type('post_tag', 'page');
}
add_action('pre_get_posts', 'cbsonline_add_page_to_tag_archive');
function cbsonline_add_page_to_tag_archive($obj)
{
if (is_tag()) {
$obj->query_vars['post_type'] = ['post', 'page'];
}
}
// override date_format option
add_filter('option_date_format', 'cbsonline_date_format');
function cbsonline_date_format($format) {
$lang = get_query_var('lang', '');
switch($lang) {
case 'ja':
return 'Y年n月j日';
case 'en_US':
return 'D, d M Y';
}
return $format;
}