2014-04-13 75 views
0
add_action('wp_enqueue_scripts', 'caffeine_load_scripts'); 

function caffeine_load_scripts(){ 
    wp_register_script('bootstrap-modal-js' , get_stylesheet_directory_uri() . '/bootstrap/bootstrap-modal.js', array('jquery'), '1', true); 
    wp_register_script('bootstrap-modal-patch-js' , get_stylesheet_directory_uri() . '/bootstrap/patch/bootstrap-modal-patch.js', array('jquery'), '1', true); 
    wp_register_script('bootstrap-modal-manager-js' , get_stylesheet_directory_uri() . '/bootstrap/patch/bootstrap-modalmanager.js', array('jquery'), '1', true); 

    wp_enqueue_style('bootstrap-css', get_stylesheet_directory_uri() . "/bootstrap/bootstrap.min.css", array(), '1', 'all'); 

    wp_enqueue_script('bootstrap-modal-js'); 
    wp_enqueue_script('bootstrap-modal-patch-js'); 
    wp_enqueue_script('bootstrap-modal-manager-js'); 

} 

那么紧随其后的是这种格式:wp_enqueue_script不页脚每个页面加载像它应该

add_action('wp_enqueue_scripts', 'remove_scripts_home', 99); 
    function remove_scripts_home() { 
     if (is_front_page() || is_home()) { 
     //here I dequeue scripts and styles not used on home page 
     } 
    } 

add_action('wp_enqueue_scripts', 'remove_scripts_about', 99); 
    function remove_scripts_about() { 
     if (is_page(412)) { 
     //here I dequeue scripts and styles not used on the about page 
     } 
    } 

他们加载网页上的页脚,但他们在头加载任何其他页面上!

有人能告诉我为什么吗?

回答

0

您需要有条件地入队您的脚本和样式表。你不能再入队和出球。

你需要做这样的事情

add_action('wp_enqueue_scripts', 'caffeine_load_scripts'); 

function caffeine_load_scripts(){ 
    if (is_front_page() || is_home()) { 
    <--- Load the scripts you need on homepage, if nothing, leave this empty ---> 
    }elseif(is_page(412)) { 
    <--- Load scripts for page 412, if nothing, leave this empty ---> 
    }else{ 
    <--- Load all your scripts ---> 
    } 

或者你可以使用

add_action('wp_enqueue_scripts', 'caffeine_load_scripts'); 

function caffeine_load_scripts(){ 
    if(false == is_front_page() || false == is_home() || false == is_page(412)) { 
    <--- load all your scripts ---> 
    } 

如果你不想装上你的这些

网页的脚本
相关问题