我使用以下代码从wp_head()注销jquery:
<?php if ( !is_admin() ) wp_deregister_script('jquery'); wp_head(); ?>我想当用户在bbpress页面上添加jquery时,但它不工作:
<?php
if (is_bbPress()) (wp_register_script('jquery'); wp_head();}
else (!is_admin()) (wp_deregister_script('jquery'); wp_head();}
?>有人能帮我解决这个问题吗?
发布于 2014-01-14 21:07:57
将脚本和样式入队的正确方法是使用wp_enqueue_script
http://codex.wordpress.org/Function_Reference/wp_enqueue_script
所以,举个例子:
function my_enqueue_script() {
if ( is_bbPress() ) {
// The name used as a handle for the script
$handle = 'script-name';
// The url to the script
$src = get_template_directory_uri() . '/js/example.js';
// Array of the handles of all the registered scripts that must be loaded before this script
$deps = array();
// The version number of the script (if it has one)
$ver = '1.0.0';
// Should the script be placed in the document footer or the head?
$in_footer = true;
wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer );
}
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_script' );https://stackoverflow.com/questions/21112794
复制相似问题