wordpress-theme-niu/functions.php

40 lines
1.2 KiB
PHP
Raw Normal View History

2022-05-10 18:38:34 +09:00
<?php
// enable automatic update
add_filter( 'auto_update_plugin', '__return_true' );
add_filter( 'auto_update_theme', '__return_true' );
add_action('wp_enqueue_scripts', 'theme_enqueue_styles');
function theme_enqueue_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri().'/style.css' );
wp_enqueue_style('child-style', get_stylesheet_directory_uri().'/style.css', ['parent-style']);
}
// enable archive page.
add_filter( 'register_post_type_args', 'post_has_archive', 10, 2 );
function post_has_archive($args, $post_type) {
if ('post' == $post_type) {
$args['rewrite'] = true;
$args['has_archive'] = 'news';
}
return $args;
}
// add google analytics
add_action('wp_head', 'hook_google_analytics');
function hook_google_analytics() {
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;
}