Skip to content

Instantly share code, notes, and snippets.

@ibrokemywp
Created January 3, 2015 12:22
Show Gist options
  • Save ibrokemywp/d8fe5d3eae6f78033ee7 to your computer and use it in GitHub Desktop.
Save ibrokemywp/d8fe5d3eae6f78033ee7 to your computer and use it in GitHub Desktop.
Two ways to enqueue an asset on an admin sub-page.
/**
* You can hook directly into the `load-{page}` hook for a sub-page with
* an action like this.
*/
add_action( 'load-myplugin-parent_page_myplugin-subpage', 'enqueue_myplugin_assets' );
/**
* Or you can hook into `admin_enqueue_scripts` and check the current
* screen to see if we're on the right page.
*/
add_action( 'admin_enqueue_scripts', 'enqueue_myplugin_assets' );
function enqueue_myplugin_assets() {
$screen = get_current_screen();
if ( !empty( $screen ) && $screen->base == 'myplugin-parent_page_myplugin-subpage' ) {
// enqueue your assets
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment