Title: Enqueueing Scripts for Theme Admin Pages
Last modified: August 20, 2016

---

# Enqueueing Scripts for Theme Admin Pages

 *  Resolved [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/)
 * According to [Make WordPress Themes](http://make.wordpress.org/themes/guidelines/changes-wp-3-3/)
   all themes must use the action `admin_enqueue_script-appearance_page_$menu_slug`
   to enqueue scripts and styles for theme pages in the admin.
 * For some reason, I can’t get this to work. I’ve created an admin page with the
   slug origin-styles. I’ve added an action for it using `add_action('admin_enqueue_script-
   appearance_page_origin-styles','origin_enqueue_function')` but `origin_enqueue_function`
   is never called.
 * I did a full regex search of wp-admin (WordPress 3.4 Beta 4) and the only place
   an action is called with the string “admin_enqueue_script” in it is on line 68
   of admin-header.php. To test, I added the following line to `admin-header.php`.
 * `do_action("admin_enqueue_script-$hook_suffix");`
 * As expected, `origin_enqueue_function` started being called after I added this.
 * Am I missing something here, or is using the action admin_enqueue_scripts still
   the only way to enqueue scripts for a theme admin page?

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704474)
 * Double check the slug on your theme options page. That’s thrown me a few time
   because I’ve used `admin_print_styles-appearance_page_theme_option` instead of`
   admin_print_styles-appearance_page_theme_options` (missing ‘s’).
 *  Thread Starter [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704495)
 * I’ve checked for typos and the like. I think everything is fine. As far as I 
   can tell, the issue is just that the `"admin_enqueue_script(s)-$hook_suffix"`
   action is never called. When I added that manually to `admin-head.php`, everything
   worked as expected.
 * The only solution I can think of is to just use `"admin_print_scripts-$hook_suffix"`
   instead, but I thought using this hook for enqueueing scripts was discouraged.
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704496)
 * `admin_enqueue_script` != `admin_enqueue_scripts`
 * The actual hook name is the latter; your example above uses the former.
 * Thanks for catching that typo; I’ve fixed it on the page you linked.
 *  Thread Starter [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704545)
 * Hi Chip, I actually thought that might be the issue so I did test it with admin_enqueue_scripts_
   $hook_name, but it still didn’t work. To test the issue I created a simple theme
   with the following functions.php
 *     ```
       function hooktest_admin_menu(){
       	add_theme_page('Test Page', 'Test Page', 'edit_theme_options', 'hooktest', 'hooktest_admin');
       }
       add_action('admin_menu', 'hooktest_admin_menu');
   
       function hooktest_admin(){
       	print 'This is the hooktest page';
       }
   
       function hooktest_admin_enqueue(){
       	error_log('hooktest_admin_enqueue');
       }
       add_action('admin_enqueue_scripts-appearance_page_hooktest', 'hooktest_admin_enqueue');
   
       function hooktest_admin_print_scripts(){
       	error_log('hooktest_admin_print_scripts');
       }
       add_action('admin_print_scripts-appearance_page_hooktest', 'hooktest_admin_enqueue');
       ```
   
 * According to this, `hooktest_admin_enqueue()` is NOT being called, while `hooktest_admin_print_scripts()`
   is being called when I view the hooktest admin page.
 * I also can’t find any evidence of a do_action that would possibly call `"admin_enqueue_scripts-
   $hook_prefix"` (or `"admin_enqueue_scripts-appearance_page_$menu_slug"`) anywhere
   in WordPress 3.4 Beta 4 or WordPress 3.3.
 * My last submission to the theme directory was rejected for (among other factors)
   not using `admin_enqueue_scripts-appearance_page_$menu_slug` – that’s the only
   reason I’m trying to get to figure this one out.
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704548)
 * If `admin_print_scripts-$hook_suffix` works, feel free to use it!
 *  Thread Starter [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704550)
 * Thanks Chip, I will do!
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704558)
 * Also, try this?
 *     ```
       function hooktest_enqueue_scripts( $hook_suffix ) {
           if ( 'appearance_page_hooktest' == $hook_suffix ) {
               wp_enqueue_script( ... );
           }
       }
       add_action( 'admin_enqueue_scripts', 'hooktest_enqueue_scripts' );
       ```
   
 * The [actual call](http://core.trac.wordpress.org/browser/tags/3.3.2/wp-admin/admin-header.php#L68)
   is:
 *     ```
       do_action('admin_enqueue_scripts', $hook_suffix);
       ```
   
 * So, you _should_ be able to pass the `$hook_suffix` as an argument into your 
   callback.
 * Either one is entirely acceptable. The point of the guideline is to ensure that
   a Theme’s admin scripts _only_ get enqueued on the Theme’s own admin settings
   page.
 *  Thread Starter [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704560)
 * I was originally using that method and it was working perfectly. According to
   my [theme submission ticket](http://themes.trac.wordpress.org/ticket/7504) it
   was one of the issues I needed to fix though.
 * I’ll stick to that method and try let the reviewer know that you said it’s acceptable.
 *  [Chip Bennett](https://wordpress.org/support/users/chipbennett/)
 * (@chipbennett)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704567)
 * No problem. I found your ticket, and left a comment regarding your original method.
 * For future reference, if your question involves the Theme Review guidelines, 
   or a specific Theme review comment, you’ll get much quicker, more specific, and
   more effective responses if you post comments _in the review ticket_. You’re 
   also welcome to post to the theme-reviewers mail list.
 * In a case such as this, don’t be shy about asking the reviewer why your method
   wasn’t acceptable. We absolutely can, do, and will make mistakes. 🙂
 *  Thread Starter [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * (@gpriday)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704614)
 * Thanks for all your help Chip! I appreciate all the hard work you and the review
   team are putting in.

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

The topic ‘Enqueueing Scripts for Theme Admin Pages’ is closed to new replies.

 * 10 replies
 * 3 participants
 * Last reply from: [Greg – SiteOrigin](https://wordpress.org/support/users/gpriday/)
 * Last activity: [14 years, 1 month ago](https://wordpress.org/support/topic/enqueueing-scripts-for-theme-admin-pages/#post-2704614)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
