2014-04-13 78 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 ---> 
    } 

如果你不想裝上你的這些

網頁的腳本
相關問題