Title: Adding javascript from plugin only on plugin page
Last modified: August 20, 2016

---

# Adding javascript from plugin only on plugin page

 *  Resolved [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/adding-javascript-from-plugin-only-on-plugin-page/)
 * Hi,
 * I have been trying to add a few javascript files to my plugin. One’s that will
   only fire when on my plugin settings page.
 * Here is what I have so far:
 *     ```
       function my_plugin_admin_init() {
           // what your plugin needs in its <head>
       	wp_register_script( 'jwl_sliding_script', plugins_url('js/jwl_admin_sliding.js', __FILE__) );
       }
       add_action( 'admin_init', 'my_plugin_admin_init' );
   
       function my_plugin_admin_styles() {
       	wp_enqueue_script( 'jwl_sliding_script' );
       }
       add_action('admin_print_styles-ultimate-tinymce', 'my_plugin_admin_styles');
       ```
   
 * But I think I have something wrong, as the script is not doing what it’s supposed
   to do.
 * Am I on the right track here?

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/adding-javascript-from-plugin-only-on-plugin-page/#post-2640599)
 * When you add your plugin page do it like this:
 *     ```
       $page = add_submenu_page( ...);
       ```
   
 * Now you can use $page in the “admin_print_styles-” action hook:
 *     ```
       add_action('admin_print_styles-' . $page, 'my_plugin_admin_styles');
       ```
   
 * It’s better explained here:
    [https://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_scripts_only_on_plugin_pages](https://codex.wordpress.org/Function_Reference/wp_enqueue_script#Load_scripts_only_on_plugin_pages)
 * or try it with get_current_screen():
    [https://codex.wordpress.org/Function_Reference/get_current_screen](https://codex.wordpress.org/Function_Reference/get_current_screen)
 *  Thread Starter [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/adding-javascript-from-plugin-only-on-plugin-page/#post-2640699)
 * Thank you, kind friend. That worked perfectly.
 * I was under the assumption you could use the `admin_print_styles` in the following
   manner; with `ultimate-tinymce` being the admin settings page.
 * `admin_print_styles-ultimate-tinymce`
 * I don’t fully understand how assigning it to a variable makes it work… but I’m
   certainly not going to argue 🙂
 * If you see this, and have time, would you mind taking a look at this thread also?
   
   [http://wordpress.org/support/topic/plugin-exportimport-options-settings?replies=1](http://wordpress.org/support/topic/plugin-exportimport-options-settings?replies=1)
 * Thanks again, kindly!!
 *  Thread Starter [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/adding-javascript-from-plugin-only-on-plugin-page/#post-2640740)
 * Forgot to mark this as resolved… My bad 🙂

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

The topic ‘Adding javascript from plugin only on plugin page’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Josh](https://wordpress.org/support/users/josh401/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/adding-javascript-from-plugin-only-on-plugin-page/#post-2640740)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
