【发布时间】:2014-06-01 17:27:16
【问题描述】:
尝试基于某些模板文件加载一些排队的 jQuery 脚本,但不让它们加载(从 functions.php 调用):
function load_doc_scripts() {
if (is_page_template('page-doc-new.php') || is_page_template('page-docs-main.php')) {
wp_register_script( 'shadowbox',
get_template_directory_uri() . '/library/js/shadowbox.js',
array('jquery'),
'1.2' );
wp_register_script( 'prettycode',
'https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=desert',
array('jquery'),
'1.2' );
wp_enqueue_script('shadowbox');
wp_enqueue_script('prettycode');
}
}
add_action('wp_enqueue_scripts', 'load_doc_scripts');
【问题讨论】:
-
这是儿童主题吗?你检查浏览器控制台是否有加载错误?
-
你的脚本是正确的。为我工作。看看你是否与functions.php中的其他脚本有任何冲突。在干净的functions.php 中尝试该函数。还要确保您在使用 page-doc-new.php 的页面模板上。
-
啊,就是这样。调用了错误的文件名,我的错。感谢您为我指明正确的方向。
标签: javascript wordpress conditional