• Resolved navyspitfire

    (@navyspitfire)


    I have <?php wp_footer(); ?> at the bottom of my footer.php page. I want to add some javascript to the footer and am unsure if I add the script before or after that line, or do I place it into another file?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator Jose Castaneda

    (@jcastaneda)

    THEME COFFEE MONKEY

    You actually want to hook to it by using wp_enqueue_script.

    add_action ( 'wp_enqueue_scripts', 'my_js_file' );
    function my_js_file(){
        wp_enqueue_scrtipt( 'my-js', path-to-tile, array(), '', true );
    }
    Thread Starter navyspitfire

    (@navyspitfire)

    Essentially I make a script.js file and add it into my /js/ folder?

    Then I add that into my functions.php file? ‘my_js_file’ I would name whatever, and ‘my-js’ would be the filename?

    How would I execute it then?

    Thread Starter navyspitfire

    (@navyspitfire)

    Why wouldn’t I want to do wp_register_script??

    Thread Starter navyspitfire

    (@navyspitfire)

    Is there any reason this wouldn’t work?

    add_action ( 'wp_enqueue_scripts', 'dtrou_youtube_api' );
    
    function dtrou_youtube_api() {
        wp_register_script( 'dtrou-youtube', get_template_directory_uri() . '/js/youtube_js.js', array('jquery'), '', true );
        wp_register_script( 'youtube-subscribe-btn', 'https://apis.google.com/js/plusone.js', array(), '', true );
        wp_register_script( 'youtube-subscribe-featured', 'https://gdata.youtube.com/feeds/users/droptroucomedy/uploads?alt=json-in-script&callback=vidinfolist&max-results=1', array(), '', true );
        wp_register_script( 'youtube-subscribe-videos', 'https://gdata.youtube.com/feeds/users/droptroucomedy/uploads?alt=json-in-script&callback=vidinfolist&max-results=100', array(), '', true );
    
    if ( is_page_template('t-featured.php') ) {
        wp_enqueue_script('dtrou-youtube');
        wp_enqueue_script('youtube-subscribe-featured');
        wp_enqueue_script('youtube-subscribe-btn');
    }
    
    if ( is_page_template('t-videos.php') ) {
        wp_enqueue_script('dtrou-youtube');
        wp_enqueue_script('youtube-subscribe-videos');
        wp_enqueue_script('youtube-subscribe-btn');
    }
    }
    Thread Starter navyspitfire

    (@navyspitfire)

    Solved. Needed to place <?php wp_footer(); ?> in my footer.php file.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding to wp_footer’ is closed to new replies.