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?
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?
<?php if (is_page('about')) {
== javascript code here ==
<?php } ?>
sub your page slug for the word about
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 !
This topic has been closed to new replies.