我正在制作一个自定义的WordPress主题。到目前为止,我所有的东西都工作得很好,除了一件事:外部JavaScript文件无法工作。
我遵循了链接中的确切建议here 和here, 但它仍然不起作用。
我搜索了法典,检查了源代码,使用了firebug。我不知道为什么这不起作用。不幸的是,由于NDA, 我不允许给你任何来自网站的实际代码,或链接到它。所以我必须尽可能地解释清楚。
我用过wp_enqueue_script()
将文件包括在functions.php
文件头部中的脚本标记如下:
<script type=\'text/javascript\' src=\'http://www.xx.com/wp-includes/js/jquery/jquery.js?ver=1.4.4\'></script>
<script type=\'text/javascript\' src=\'http://www.xx.com/wp-content/themes/twentyten/scripts/custom.js?ver=3.1\'></script>
因此,文件正在加载,但无法正常工作。我想知道?ver=3.1
在我的custom.js
文件可能与此有关?我的functions.php
文件:
function twentyten_custom_scripts() {
if ( !is_admin() ) // instruction to only load if it is not the admin area
{
// register your script location, dependencies and version
wp_register_script(\'custom_script\', get_bloginfo(\'template_directory\') . \'/scripts/custom.js\', array(\'jquery\') );
// enqueue the script
wp_enqueue_script( \'jquery\' );
wp_enqueue_script(\'custom_script\');
}
}
add_action(\'template_redirect\', \'twentyten_custom_scripts\');
在这一点上我真的迷路了。我甚至改变了我的:$(\'#elem\').hide();
至jQuery(\'#elem\').hide();
在custom.js
根据法典归档wp_enqueue_script()
无冲突包装器部分here, 还是没什么。哦,我需要将此文件加载到我的所有页面中,但不能加载到我的博客中,因为我为主站点设置了多个静态页面。我希望这是有意义的。