无法在自定义WordPress主题

时间:2016-02-14 05:52:52

标签: javascript jquery wordpress wordpress-theming

我正在将Bootstrap模板转换为WordPress主题,我已经在functions.php中引用了我的所有样式表和脚本,以及footer.php中的一些初始化代码,但是有一个特定的文件未正确执行:http://blackrockdigital.github.io/startbootstrap-creative/js/creative.js

脚本:

(function($) {
    "use strict"; // Start of use strict

    // jQuery for page scrolling feature - requires jQuery Easing plugin
    $('a.page-scroll').bind('click', function(event) {
        var $anchor = $(this);
        $('html, body').stop().animate({
            scrollTop: ($($anchor.attr('href')).offset().top - 50)
        }, 1250, 'easeInOutExpo');
        event.preventDefault();
    });

    // Highlight the top nav as scrolling occurs
    $('body').scrollspy({
        target: '.navbar-fixed-top',
        offset: 51
    })

    // Closes the Responsive Menu on Menu Item Click
    $('.navbar-collapse ul li a:not(.dropdown-toggle)').click(function() {
        $('.navbar-toggle:visible').click();
    });

    // Fit Text Plugin for Main Header
    $("h1").fitText(
        1.2, {
            minFontSize: '35px',
            maxFontSize: '65px'
        }
    );

    // Offset for Main Navigation
    $('#mainNav').affix({
        offset: {
            top: 100
        }
    })

    // Initialize WOW.js Scrolling Animations
    new WOW().init();

})(jQuery); // End of use strict

我已将此特定文件设置为使用jQuery,并通过functions.php在</body>标记之前调用,但内部没有任何脚本正在执行,Chrome正在返回此错误:

Uncaught TypeError: $(...).scrollspy is not a function

我尝试用$替换jQuery别名,但它没有效果。我也确认这是在jQuery库之后调用的。

任何帮助都会非常感激。谢谢!

1 个答案:

答案 0 :(得分:0)

我想您忘记链接bootstrap.min.js或正确链接

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>