WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Help with wp_enqueue (4 posts)

  1. vikkineal
    Member
    Posted 1 year ago #

    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...

  2. vikkineal
    Member
    Posted 1 year ago #

    I'm now wondering whether i need to register the script?

  3. vikkineal
    Member
    Posted 1 year ago #

    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...

  4. vikkineal
    Member
    Posted 1 year ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic