javascript - 在 Wordpress 中使用 Slicknav

标签 javascript jquery html wordpress slicknav

我见过一些人问过这个问题,但我似乎无法在我的网站上获得任何其他建议。我正在尝试在我正在工作的 Wordpress 网站上使用 slicknav.js 并且它根本不起作用。我曾经让它工作过,但不幸的是不得不废弃该站点并重新开始,现在我无法让它工作。 我做了一些测试,才意识到我的脚本都没有加载。 wp_enqueue_scripts() 根本没有传递我的任何脚本。知道我可能做了什么来破坏它吗?

我在本地开发,所以我不能给链接...但这是我所有的代码。

函数.php

<?php
// WP Enqueue Styles
function wop_styles() {
    wp_enqueue_style( 'normalize_css' , get_template_directory_uri() .     '/css/normalize.css' );
    wp_enqueue_style( 'fontawesome_css' , 'https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css' );
    wp_enqueue_style( 'googleFonts_css' , 'https://fonts.googleapis.com/css?family=Montserrat:400,700|Roboto+Slab:400,700|Satisfy' );
    wp_enqueue_style( 'slicknav_css' , 'https://cdnjs.cloudflare.com/ajax/libs/SlickNav/1.0.5.5/slicknav.min.css');
    wp_enqueue_style( 'style_css' , get_template_directory_uri() . '/css/compile.css' );
}
add_action( 'wp_enqueue_scripts' , 'wop_styles' );

// WP Enqueue Scripts
function wop_scripts() {
    wp_enqueue_script( 'slicknav_js' , 'https://cdnjs.cloudflare.com/ajax/libs/SlickNav/1.0.5.5/jquery.slicknav.min.js' , array('jQuery_js', 'slicknav_css') , true);
    wp_enqueue_script( 'theme_js' , get_template_directory_uri() . '/js/theme.js' , array('jQuery_js'), true );
}
add_action( 'wp_enqueue_scripts' , 'wop_scripts' );

我的 Theme.js 文件:

(function($){
   $('menu-header-menu').slicknav(); 
})(jQuery);

最后,这是我的 HTML 标记。

<header class="page-header"> <!--- BEGIN .page-header --->
            <div class="branding">
            </div>
            <nav>
                <?php wp_nav_menu(array('theme_location' => 'header-menu', 'container' => false,)); ?>
            </nav>
        </header> <!--- END .page-header --->

<footer class="page-footer"> <!--- BEGIN .page-footer --->
        <?php wp_footer(); ?>
    </footer> <!--- END .page-footer --->
    </body> <!--- END .page-outer-wrapper -->
</html>

我的页脚没有显示任何脚本,即使我更改了 $in-footer = false,Nothin。

显然我在页眉和页脚之间有一些东西,但我认为这些是唯一真正重要的部分..

有什么想法吗?

最佳答案

$in_footer
(boolean) (optional) Normally scripts are placed in the <head> section. If this parameter is true the script is placed at the bottom of the <body>. This requires the theme to have the wp_footer() hook in the appropriate place. Note that you have to enqueue your script before wp_head is run, even if it will be placed in the footer.

如果我没理解错的话。您想在页脚中调用脚本,但您的 HTML 标记不包含页脚吗?

要在 header ($in-footer=false) 中排队脚本,它必须在 wp_head() 调用之前。

引用:http://codex.wordpress.org/Function_Reference/wp_register_script

关于javascript - 在 Wordpress 中使用 Slicknav,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35213128/

相关文章:

javascript - 我可以使用揭示模式将 ES6 JavaScript 程序分解为单独的文件吗?

javascript - Jasmine SpyOn 关于函数调用

javascript - CSS 在移动设备上消失

PHP - 打开 2 个 Html 页面

html - 屏幕尺寸缩小时样式困惑

html - chrome 的 -webkit-focus-ring-color 等效于什么

javascript - Kendo UI Drop Down 从模型加载数据

javascript - AngularJS - 为什么需要模块依赖?

javascript - D3 arc tweening 不工作

jquery - Div 覆盖内容