Title: WP 3.0 &#8211; Problems enqueueing javascript with specific target
Last modified: August 20, 2016

---

# WP 3.0 – Problems enqueueing javascript with specific target

 *  Resolved [victheone](https://wordpress.org/support/users/victheone/)
 * (@victheone)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp-30-problems-enqueueing-javascript-with-specific-target/)
 * My organization requires that I use WordPress 3.0 to create a new plugin. I’m
   having trouble getting one of my scripts to load to *only* my Options page (accessed
   as admin from the dashboard). When I enqueue it without a target page hook, the
   script successfully loads on every page, but I don’t want that. Here’s a few 
   code snippets:
 * In my sidebar loader:
    `define( OPTIONS_PAGE, add_menu_page('EMS Forms Options','
   EMS Forms', 'manage_options', PATH.'/EMSF_Options.php') );`
 * In my main file:
    `add_action('admin_print_scripts-'.OPTIONS_PAGE, 'Add_EMSF_Options_Scripts');`
 * And here’s the function that the main file is assigning the action…
 *     ```
       function Add_EMSF_Options_Scripts(){
       wp_register_script('EMSF_Options, plugins_url('emsforms/js/EMSF_Options.js'), array('jquery','jquery-form'), '1.0');
       wp_enqueue_script('EMSF_Options');
       }
       ```
   
 * Any help with this would be greatly appreciated. I suppose I could just let it
   load the script on every page, but I’d rather not, since it uses jquery’s ajax
   functionality every time it loads.
 * Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp-30-problems-enqueueing-javascript-with-specific-target/#post-2301322)
 * > accessed as admin from the dashboard
 * Use [is_admin()](http://codex.wordpress.org/Function_Reference/is_admin) or [is_user_logged_in()](http://codex.wordpress.org/Function_Reference/is_user_logged_in)
 *     ```
       function Add_EMSF_Options_Scripts(){
       	if( is_admin() ) {
       		wp_register_script('EMSF_Options, plugins_url('emsforms/js/EMSF_Options.js'), array('jquery','jquery-form'), '1.0');
       		wp_enqueue_script('EMSF_Options');
   
       	}
       }
       ```
   
 * I have just read it again, is there something in the url that you can use as 
   a condition, try to echo $pagename and see what it returns and then?
 *     ```
       function Add_EMSF_Options_Scripts(){
       	global $pagenow;
       	if ( $pagenow == 'emsf_options.php' ) {
       	if( is_admin() ) {
       		wp_register_script('EMSF_Options, plugins_url('emsforms/js/EMSF_Options.js'), array('jquery','jquery-form'), '1.0');
       		wp_enqueue_script('EMSF_Options');
   
       	}
       }
       ```
   
 * HTH
 * David
 *  Thread Starter [victheone](https://wordpress.org/support/users/victheone/)
 * (@victheone)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp-30-problems-enqueueing-javascript-with-specific-target/#post-2301336)
 * The second method (using strpos to find the page name in the URL) would almost
   certainly work for me, but $pagenow is empty. Were you just using that as an 
   example, or is that actually supposed to be a wordpress global var?
 *  [Digital Raindrops](https://wordpress.org/support/users/adeptris/)
 * (@adeptris)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp-30-problems-enqueueing-javascript-with-specific-target/#post-2301348)
 * I got the syntax wrong, I was developing a plugin, here is the options code snippet
   that may help.
 *     ```
       global $pagenow;
       if ( $pagenow == 'admin.php' && $_GET['page'] == 'raindrops' ) :
       ```
   
 * So if it is an options page check the url for the $pagenow and the page will 
   be your pagename, mine was raindrops.php so ‘raindrops’
 *     ```
       global $pagenow;
       if ( $pagenow == 'admin.php' && $_GET['page'] == ''emsf_options' ) :
       ```
   
 * I have used the global `$pagenow` in a plugin for `$pagenow == 'post.php'` and`
   $pagenow == 'new-post.php'` so I know it works, not sure from which version as
   I always have the latest.
 * If I run the wp-pagenavi options page I have:
    `wp-admin/options-general.php?
   page=pagenavi`
 * That would be:
 *     ```
       global $pagenow;
       if ( $pagenow == 'admin.php' && $_GET['page'] == 'pagenavi' ) :
       ```
   
 * or:
 *     ```
       global $pagenow;
       if ( $pagenow == 'options.php' && $_GET['page'] == 'pagenavi' ) :
       ```
   
 * or:
 *     ```
       global $pagenow;
       if ( $pagenow == 'general-options.php' && $_GET['page'] == 'pagenavi' ) :
       ```
   
 * HTH
 * David
 *  Thread Starter [victheone](https://wordpress.org/support/users/victheone/)
 * (@victheone)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/wp-30-problems-enqueueing-javascript-with-specific-target/#post-2301567)
 * That fixed it! Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘WP 3.0 – Problems enqueueing javascript with specific target’ is closed
to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [enqueue](https://wordpress.org/support/topic-tag/enqueue/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [WP 3.0](https://wordpress.org/support/topic-tag/wp-3-0/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [victheone](https://wordpress.org/support/users/victheone/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/wp-30-problems-enqueueing-javascript-with-specific-target/#post-2301567)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
