2022-05-10 18:38:34 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// enable automatic update
|
2022-06-07 19:33:46 +09:00
|
|
|
add_filter('auto_update_core', '__return_true');
|
|
|
|
add_filter('auto_update_theme', '__return_true');
|
|
|
|
add_filter('auto_update_plugin', '__return_true');
|
|
|
|
add_filter('auto_update_translation', '__return_true');
|
|
|
|
|
|
|
|
// load and overrride style of parent theme
|
|
|
|
add_action('wp_enqueue_scripts', 'niu_theme_enqueue_styles');
|
|
|
|
function niu_theme_enqueue_styles()
|
|
|
|
{
|
|
|
|
wp_enqueue_style('parent-style', get_template_directory_uri().'/style.css');
|
2022-05-10 18:38:34 +09:00
|
|
|
wp_enqueue_style('child-style', get_stylesheet_directory_uri().'/style.css', ['parent-style']);
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable archive page.
|
2022-06-07 19:33:46 +09:00
|
|
|
add_filter('register_post_type_args', 'niu_post_has_archive', 10, 2);
|
|
|
|
function niu_post_has_archive($args, $post_type)
|
|
|
|
{
|
2022-05-10 18:38:34 +09:00
|
|
|
if ('post' == $post_type) {
|
|
|
|
$args['rewrite'] = true;
|
2022-06-07 19:33:46 +09:00
|
|
|
$args['has_archive'] = 'news';
|
2022-05-10 18:38:34 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return $args;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add google analytics
|
2022-06-07 19:33:46 +09:00
|
|
|
add_action('wp_head', 'niu_add_google_analytics');
|
|
|
|
function niu_add_google_analytics()
|
|
|
|
{
|
2022-05-10 18:38:34 +09:00
|
|
|
echo <<<EOF
|
|
|
|
|
|
|
|
<!-- Google Tag Manager -->
|
|
|
|
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
|
|
|
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
|
|
|
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|
|
|
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
|
|
|
})(window,document,'script','dataLayer','GTM-K6BD5N9');</script>
|
|
|
|
<!-- End Google Tag Manager -->
|
|
|
|
|
|
|
|
EOF;
|
|
|
|
}
|
2022-06-07 19:33:46 +09:00
|
|
|
|
|
|
|
// disable oembed if url is not my site url
|
|
|
|
add_filter('oembed_request_post_id', 'niu_check_oembed_url', 10, 2);
|
|
|
|
function niu_check_oembed_url($post_id, $url)
|
|
|
|
{
|
|
|
|
if (!preg_match('/^'.preg_quote(get_site_url(), '/').'/', $url)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $post_id;
|
|
|
|
}
|