Wordpress 如何筛选某些页面上的wp_enqueue_script()脚本

Wordpress 如何筛选某些页面上的wp_enqueue_script()脚本,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我使用以下代码在WP页面中添加一些脚本,如 function add_js() { wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", false, null); wp_enque

我使用以下代码在WP页面中添加一些脚本,如

function add_js() {
  wp_deregister_script('jquery');
  wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js", false, null);
  wp_enqueue_script('jquery');
  wp_enqueue_script( 'bootstrap-js', get_template_directory_uri() .'/js/bootstrap.min.js', array('jquery'),'',true );
  wp_enqueue_script( 'colorbox-js', get_template_directory_uri() .'/js/jquery.colorbox-min.js', array('jquery'),'',true );
  wp_enqueue_script( 'img-loader', get_template_directory_uri() .'/js/img-load.js', array('jquery'),'',true );
  wp_enqueue_script( 'box-tanzim', get_template_directory_uri() .'/js/tanzim.js', array('jquery'),'',true );
  wp_enqueue_script( 'scripts-js', get_template_directory_uri() .'/js/scripts.js', array('jquery'),'',true );

}
add_action( 'wp_enqueue_scripts', 'add_js' );
但我不想在某些页面上添加不必要的脚本!例如,我希望在
front page.php
上有上述所有脚本,但在其他页面上,我不需要最后三个脚本

你能告诉我如何过滤它们吗


谢谢

也许是这样的吧

if ( is_page_template( 'front-page.php' ) ) {
    // wp_enqueue_script()
} 

嗨,达瓦尔,我也可以使用其他模板的代码吗?例如
if(is_page_template('page products.php'){//wp_enqueue_script()}
Thanks我认为这不应该是个问题,但只要确保文件路径正确。
path of file
是什么意思?它们不是都在主题文件夹中吗?如果你的文件在子文件夹中,那么你必须考虑到这一点。例如:is_page_template('templates/about.php');有关更多信息,请参阅