2013-06-18 4 views
4

wp_enqueue_script()를 통해 두 개의 스크립트를로드하려고합니다. 함수를 만들었지 만 첫 번째로드는 두 번째로드가 아닙니다. 다음은 코드입니다.wp_enqueue_script()가 여러 스크립트를로드하지 않습니다.

//Load my own jQuery 
function fix_noconflict() { 
wp_deregister_script('jquery'); 
wp_register_script('jquery' , 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js');} 

add_action('wp_enqueue_scripts' , 'fix_noconflict'); 

//This two functions follow the same 
function mauricio_bootstrap_script_jquery() { 

//Includes bootstrap jQuery 
wp_register_script('custom-script', get_template_directory_uri().'/mauricio_bootstrap/js/bootstrap.js', array('jquery')); 

//This enqueus the script 

wp_enqueue_script('custom-script'); 
} 
// Adds the new bootstrap function to the wp_enqueue_scripts 
add_action('wp_enqueue_scripts', 'mauricio_bootstrap_script_jquery'); 

function mauricio_bootstrap_script_carousel() { 

wp_register_script('myscript', get_template_directory_uri().'/mauricio_bootstrap/js/bootstrap-carousel.js', array('jquery')); 


wp_enqueue_script('myscript'); 
} 

add_action('wp_enqueue_script', 'mauricio_bootstrap_script_carousel'); 

내 머리 속에 wp_head()가 있습니다. 그리고 bootstrap.js가 포함 된 첫 번째 함수가로드됩니다.

감사합니다,

M이 제공하는 워드 프레스 포럼에서

답변

9

사용된다 이거?

function wpEnqueueScripts(){ 
    // Adds the new bootstrap function to the wp_enqueue_scripts 
    wp_register_script('custom-script', get_template_directory_uri() . '/mauricio_bootstrap/js/bootstrap.js', array('jquery')); 
    wp_enqueue_script('custom-script'); 

    // Adds the new bootstrap function to the wp_enqueue_scripts 
    wp_register_script('myscript', get_template_directory_uri() . '/mauricio_bootstrap/js/bootstrap-carousel.js', array('jquery')); 
    wp_enqueue_script('myscript'); 
}  

add_action('wp_enqueue_scripts', 'wpEnqueueScripts'); 
+1

이것은 올바른 답변입니다. 깨끗하고, 쉽고, 한 곳에서 모두. –

+0

이것은 또한 완벽하게 작동합니다! 감사 – mauricioSanchez

1

사람. , 두 가지 기능을 합하고, 'template_redirect'의 사용 동작을 추가 할 때 $ 태그 대신 당신은 메인 함수 내에서 모든 기능을 넣어하려고하지는 왜 'wp_enqueue_script'

function mauricio_bootstrap_scripts() { 
wp_register_script('custom-script', get_template_directory_uri().'/mauricio_bootstrap/js/bootstrap.js', array('jquery')); 
wp_enqueue_script('custom-script'); 

wp_register_script('myscript', get_template_directory_uri().'/mauricio_bootstrap/js/bootstrap-carousel.js', array('jquery')); 
wp_enqueue_script('myscript'); 
} 
add_action('template_redirect', 'mauricio_bootstrap_scriptsl'); 
관련 문제