Support » Fixing WordPress » How to add javascript code in header for 1 page only!!

  • ApnaySMS

    (@apnaysms)


    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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • stvwlf

    (@stvwlf)

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

    sub your page slug for the word about

    Justin Tadlock

    (@greenshady)

    WordPress God

    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

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

    Enjoy !

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add javascript code in header for 1 page only!!’ is closed to new replies.