Conditional add script to footer:

Community Forums Forums Design Tips and Tricks Conditional add script to footer:

This topic is: not resolved

This topic contains 1 reply, has 2 voices, and was last updated by  Sridhar Katakam 9 months, 1 week ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #68600

    jgk
    Participant
    Post count: 16

    Hi, I’m attempting to add some js scripts to the footer, but only on one page of the site. I cannot find a code snippet for this online. Thanks so much for any help. Here’s what I have pasted into functions.php that isn’t working now:

    
    add_action( 'genesis_after_footer', 'scripts_footer_services_page' );
    /**
     * Enqueue Scripts
     */
    
    function scripts_footer_services_page() {
    
    	if ( is_single('482') ) {
          	wp_enqueue_script( 'services-1', get_stylesheet_directory_uri() . '/js/services-1.js', array( 'jquery' ), '', true );
    		wp_enqueue_script( 'services-2', get_stylesheet_directory_uri() . '/js/services-2.js', array( 'jquery' ), '', true );
    	}
    }
    http://studioissa.com/services/
    #68608

    Sridhar Katakam
    Participant
    Post count: 926

    Change that to

    //* Enqueue scripts
    add_action( 'wp_enqueue_scripts', 'scripts_footer_services_page' );
    function scripts_footer_services_page() {
    
    	if ( is_single('482') ) {
    		wp_enqueue_script( 'services-1', get_stylesheet_directory_uri() . '/js/services-1.js', array( 'jquery' ), '', true );
    		wp_enqueue_script( 'services-2', get_stylesheet_directory_uri() . '/js/services-2.js', array( 'jquery' ), '', true );
    	}
    }

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.