WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Help with wp_enqueue

[Resolved] Help with wp_enqueue

  • Hi

    I’m trying to add supersized via wp_enqueue and only on certain pages – but without much luck.

    I’ve currently got the query in the footer with the following PHP – THIS WORKS..

    <?php if ( !( is_page_template('modelPages.php') || is_archive() || is_single() || is_page_template('contactUsTemplate.php') ) ) { ?>
    <script type="text/javascript" src="<?php echo bloginfo('template_directory');?>/scripts/supersized.3.2.7.min.js"></script>
    <script type="text/javascript" src="<?php echo bloginfo('template_directory');?>/theme/supersized.shutter.min.js"></script>
    <?php } ?>

    However, trying to port that over to my functions file seems to just break super sized full stop…

    function custom_scripts() {
    	if ( !is_admin() ) {
    	wp_deregister_script('jquery');
    	wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"), false);
    	wp_enqueue_script('jquery');
    }
    if( is_page( 'home' ) ) :
    	wp_enqueue_script(
    	'jcarousel',
    	get_template_directory_uri() . '/scripts/jquery.jcarousel.min.js',
    	array( 'jquery' ),
    	null,
    	true
    );
    elseif( is_single() ) :
    	wp_enqueue_script(
    	'slimbox',
    	get_template_directory_uri() . '/scripts/slimbox2.js',
    	array( 'jquery' ),
    	null,
    	true
    );
    elseif( !(is_page_template('modelPages.php') || is_archive() || is_single() || is_page_template('contactUsTemplate.php')  )  ) :
        // SUPERSIZED SHOULD GO HERE BUT BREAKS
    endif;
    }    
    
    add_action( 'wp_enqueue_scripts', 'custom_scripts' );

    It just doesn’t load it at all – not even if i add it to the home rule.

    Can someone please advise on what I’m doing wrong? I clearly am getting in a muddle about adding multiple enqueues to a rule…

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m now wondering whether i need to register the script?

    Ok – so registering the script makes it load on the page HOWEVER I’m getting the following error…

    Error: TypeError: api is undefined

    and the images aren’t loading…

    Figured it out – my function were loading before the wp_enqueue had been called so was throwing an error.

    Swapped the order round and it’s now fine!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Help with wp_enqueue’ is closed to new replies.