在wordpress上安装倒计时

Countdown installation on wordpress

我尝试在 wordpress 网站上安装基本倒计时 (View Countdown),但没有任何反应。

我使用的 WordPress 主题是 "HTML5Blank"。我像这样排队 JavaScript 个文件:

wp_register_script('jquery.plugin.min.js', get_template_directory_uri() . '/js/jquery.plugin.min.js', array('jquery'), '1.0.0'); // Custom scripts
wp_enqueue_script('jquery.plugin.min.js'); // Enqueue it!

wp_register_script('jquery.countdown.js', get_template_directory_uri() . '/js/jquery.countdown.js', array('jquery'), '1.0.0'); // Custom scripts
wp_enqueue_script('jquery.countdown.js'); // Enqueue it!

index.php 主持 div:

<div id="defaultCountdown"></div>

初始化于header.php:

<script>
    (function ($) {
        var austDay = new Date();
        austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
        $('#defaultCountdown').countdown({
            until: austDay
        });
        $('#year').text(austDay.getFullYear());
    })(jQuery);
</script>

它没有填充,因为 #defaultCountdown 元素不在 DOM/loaded 中,但是当您在 <div id="defaultCountdown"></div> 之后移动脚本时,JQuery 得到了元素并且成功了。

wp_footer 之后 footer.php 中的初始化脚本。

<?php wp_footer(); ?>
<script>
    (function ($) {
        var austDay = new Date();
        austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
        $('#defaultCountdown').countdown({
            until: austDay
        });
        $('#year').text(austDay.getFullYear());
    })(jQuery);
</script>