wordpress-theme-cbsonline/functions.php

217 lines
6.9 KiB
PHP
Raw Normal View History

2020-10-29 23:50:19 +09:00
<?php
defined('ABSPATH') || exit();
// enable auto update
add_filter('allow_major_auto_core_updates', '__return_true');
add_filter('allow_minor_auto_core_updates', '__return_true');
add_filter('auto_update_theme', '__return_true');
add_filter('auto_update_plugin', '__return_true');
// remove parent theme defined filters and actions
add_action('after_setup_theme', 'cbsonline_disable_parent_defines');
2020-11-01 16:39:22 +09:00
function cbsonline_disable_parent_defines()
{
2020-10-29 23:50:19 +09:00
// remove web fonts
2020-11-01 16:39:22 +09:00
remove_action('wp_enqueue_scripts', 'biz_vektor_addWebFonts');
2020-10-29 23:50:19 +09:00
// remove buggy biz_vector script
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'biz_vektor_addJScripts');
2020-11-12 16:27:19 +09:00
// remove pingback css
remove_action('wp_enqueue_scripts','biz_vektor_addPingback');
2020-10-29 23:50:19 +09:00
}
// disable emoji
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
// add_filter('tiny_mce_plugins', 'disable_emojis_tinymce');
// remove unnecessary head tags
// - rest
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'rest_output_link_wp_head');
2020-10-29 23:50:19 +09:00
// - embed
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('wp_head', 'wp_oembed_add_host_js');
2020-10-29 23:50:19 +09:00
// - feed
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'feed_links_extra', 3);
2020-10-29 23:50:19 +09:00
// - rsd
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'rsd_link');
2020-10-29 23:50:19 +09:00
// - windows live writer
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'wlwmanifest_link');
2020-10-29 23:50:19 +09:00
// - generator
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'wp_generator');
2020-10-29 23:50:19 +09:00
// - shortlink
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'wp_shortlink_wp_head');
2020-10-29 23:50:19 +09:00
// - rel link
2020-11-01 16:39:22 +09:00
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'parent_post_rel_link', 10);
remove_action('wp_head', 'start_post_rel_link', 10);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
2020-10-29 23:50:19 +09:00
// disable automatically appending srcset attribute in img tag
add_filter('wp_calculate_image_srcset_meta', '__return_null');
// disable DNS prefetch
add_filter('wp_resource_hints', 'cbsonline_remove_dns_prefetch', 10, 2);
2020-11-01 16:39:22 +09:00
function cbsonline_remove_dns_prefetch($hints, $relation_type)
{
if ('dns-prefetch' === $relation_type) {
return array_diff(wp_dependencies_unique_hosts(), $hints);
2020-10-29 23:50:19 +09:00
}
2020-11-01 16:39:22 +09:00
2020-10-29 23:50:19 +09:00
return $hints;
}
// add styles
add_action('wp_enqueue_scripts', 'cbsonline_add_styles');
2020-11-01 16:39:22 +09:00
function cbsonline_add_styles()
{
2020-10-29 23:50:19 +09:00
wp_enqueue_style('parent-style', get_template_directory_uri().'/style.css');
wp_enqueue_style('dashicons');
}
// add scripts
add_action('wp_head', 'cbsonline_add_scripts');
2020-11-01 16:39:22 +09:00
function cbsonline_add_scripts()
{
2020-10-29 23:50:19 +09:00
wp_register_script('biz-vektor-fix-min-js', get_stylesheet_directory_uri().'/js/biz-vektor-fix-min.js', ['jquery'], '20201029');
wp_enqueue_script('biz-vektor-fix-min-js');
}
// add widgets
2020-11-01 16:39:22 +09:00
function cbsonline_widgets_init()
{
register_sidebar([
'name' => 'ヘッダー ウィジェット',
'id' => 'header-widget-area',
'before_widget' => '<div class="header-widget-area">',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
]);
register_sidebar([
'name' => 'トップバナー ウィジェット',
'id' => 'topbnr-widget-area',
'before_widget' => '<div class="topbnr-widget-area clearfix"><div class="topbnr-widget-area-inner clearfix">',
'after_widget' => '</div></div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
]);
register_sidebar([
'name' => 'トップイメージ ウィジェット',
'id' => 'topimg-widget-area',
'before_widget' => '<div class="topimg-widget-area clearfix">',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
]);
2020-10-29 23:50:19 +09:00
}
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()
2020-11-01 16:39:22 +09:00
{
2020-10-29 23:50:19 +09:00
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)
2020-11-01 16:39:22 +09:00
{
return str_replace(' (United States)', '', $output);
2020-10-29 23:50:19 +09:00
}
// add short code
// - topbox : http://www.webopixel.net/wordpress/53.html
2020-11-01 16:39:22 +09:00
function cbsonline_shortcode_TopBox($atts, $content = null)
{
$content = do_shortcode(shortcode_unautop($content));
2020-10-29 23:50:19 +09:00
extract(shortcode_atts(['class' => 'default'], $atts));
2020-11-01 16:39:22 +09:00
2020-10-29 23:50:19 +09:00
return '<div class="topbox">'.$content.'</div>';
}
add_shortcode('topbox', 'cbsonline_shortcode_TopBox');
2020-11-12 16:15:45 +09:00
// allow additional image file upload
add_filter('upload_mimes', 'cbsonline_allow_additional_image_upload');
function cbsonline_allow_additional_image_upload($mimes)
2020-11-01 16:39:22 +09:00
{
$mimes['ai'] = 'image/x-illustrator';
2020-11-12 16:15:45 +09:00
$mimes['ico'] = 'image/vnd.microsoft.icon';
2020-11-01 16:39:22 +09:00
2020-10-29 23:50:19 +09:00
return $mimes;
}
// force override Archive widget arguments
2020-11-01 16:39:22 +09:00
add_filter('widget_archives_args', 'cbsonline_widget_archives_args');
function cbsonline_widget_archives_args($args)
{
// yearly
2020-10-29 23:50:19 +09:00
$args['type'] = 'yearly';
// maximum number of items : 10 years
$args['limit'] = 10;
2020-11-01 16:39:22 +09:00
2020-10-29 23:50:19 +09:00
return $args;
}
// support category based archives
add_filter('getarchives_join', 'cbsonline_category_getarchives_join', 10, 2);
2020-11-01 16:39:22 +09:00
function cbsonline_category_getarchives_join($join, $r)
{
2020-10-29 23:50:19 +09:00
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);
2020-11-01 16:39:22 +09:00
function cbsonline_category_getarchives_where($where, $r)
{
2020-10-29 23:50:19 +09:00
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);
2020-11-01 16:39:22 +09:00
function cbsonline_category_year_link($url, $year)
{
2020-10-29 23:50:19 +09:00
global $wp_rewrite;
if (is_category()) {
$cat = intval(get_query_var('cat'));
if ($cat > 0) {
$url .= '?cat='.get_query_var('cat');
}
}
2020-11-01 16:39:22 +09:00
2020-10-29 23:50:19 +09:00
return $url;
}
2020-11-01 16:39:22 +09:00
// 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'];
}
}