Loading scripts on specific page

method two won’t work because no page is loaded yet and $post isn’t set when your if check runs.

with method one again $post is not yet set at that point, but this method will work if you use WordPress conditionals:

function load_slider(){
  if( is_page(11746) ){ //  Load slider on home page
    wp_register_script('start-slidorion', get_bloginfo('stylesheet_directory') . '/js/slidorion/start.js', array('slidorion', 'jquery','easing') );
    wp_enqueue_script('start-slidorion' );
  }
} 
add_action('wp_enqueue_scripts', 'load_slider');

EDIT another example using has_term:

function load_slider(){
    global $post;   
    if( has_term( 'your category', 'category', $post ) ):
        // enqueue your script
    endif;
} 
add_action('wp_enqueue_scripts', 'load_slider');

Leave a Comment