WordPress.org

Ready to get started?Download WordPress

Forums

How to add javascript code in header for 1 page only!! (4 posts)

  1. ApnaySMS
    Member
    Posted 5 years ago #

    How to add javascript code in header for 1 page only!!

    i want to add js code in just one page how can i do this?

  2. stvwlf
    Member
    Posted 5 years ago #

    <?php if (is_page('about')) {
       ==   javascript code here ==
    <?php } ?>

    sub your page slug for the word about

  3. Justin Tadlock
    Member
    Posted 5 years ago #

    Add this to your theme's functions.php file:

    if ( is_page( 'about' ) {
    	wp_enqueue_script( 'unique-id', get_stylesheet_directory_uri() . '/name-of-file.js', false, 0.1 );
    }

    Just change the name and/or directory of the file. You might also want to change unique-id.

    Sources:
    http://codex.wordpress.org/Function_Reference/wp_enqueue_script

  4. maghis
    Member
    Posted 4 years ago #

    If you use greenshady's code above there is a ) missing in the first line:
    if ( is_page( 'about' )) {

    Enjoy !

Topic Closed

This topic has been closed to new replies.

About this Topic