WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following function within my functions.php loads a JS script..

function my_scripts_method() {
        get_template_directory_uri() . '/js/dropdown.jquery.min.js',

add_action('wp_enqueue_scripts', 'my_scripts_method');

How could i modify this function so that the JS script is loaded only on specified pages (perhaps by providing their ID in the function's arguments..)

share|improve this question
up vote 0 down vote accepted

You can use conditional tag such as is_page(). Register your script on hook wp_enqueue_scripts and enqueue it in if statement :

    get_template_directory_uri() . '/js/dropdown.jquery.min.js',

if (is_page(PAGEID)) { wp_enqueue_script('myashdrop'); }
share|improve this answer
thanks but i am also using multiple pages and looking for optimum syntax.. can i separate PAGEID by commas ? – Mario Lorenzo Jun 20 '13 at 17:15
sure, in array: is_page(array(ID1,iD2)) – JMau Jun 20 '13 at 17:17
last question ! how can i enqueue multiple scripts at the same time using the is_page(PAGEID) syntax .. ? – Mario Lorenzo Jun 20 '13 at 18:03
You can use multiple register_script and wp_enqueue_script – JMau Jun 20 '13 at 18:05
ok so i can't use array in there... ? i need to repeat wp_enqueue – Mario Lorenzo Jun 20 '13 at 18:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.