Wordpress - 在某些帖子类型上禁用jQuery脚本

时间:2013-01-27 15:29:20

标签: php jquery wordpress

我正在尝试取消注册wordpress上的一些脚本,但仅适用于某些帖子类型。我仍然是wordpress和php的新手,所以我很难弄清楚这是怎么做的 这是我的注册&排队的剧本:

function test_script_method() {
    wp_register_script( 'jq', '/wp-content/themes/test/js/script.js');
    wp_enqueue_script( 'jq' );
    wp_register_script( 'slideshow', '/wp-content/themes/test/js/slideshow.js');
    wp_enqueue_script( 'slideshow' );
}
add_action('wp_enqueue_scripts', 'test_script_method');

所以我将jQuery分成两个文件,因为我不需要在某些页面/帖子类型上使用它们。

首先,我尝试为帖子类型为'jq'的所有帖子以及'news'和标题为'archive-news.php'的页面上的所有帖子停用'home'脚本。
这是可能吗?

1 个答案:

答案 0 :(得分:0)

这样的东西?

enterfunction test_script_method() {
   global $wp_query;
   if ( "news" != get_post_type() && !(is_page('home')) ) {
    wp_register_script( 'jq', '/wp-content/themes/test/js/script.js');
    wp_enqueue_script( 'jq' );
    wp_register_script( 'slideshow', '/wp-content/themes/test/js/slideshow.js');
    wp_enqueue_script( 'slideshow' );
   }
}
add_action('wp_enqueue_scripts', 'test_script_method'); code here
相关问题