Created
January 3, 2015 12:22
-
-
Save ibrokemywp/d8fe5d3eae6f78033ee7 to your computer and use it in GitHub Desktop.
Two ways to enqueue an asset on an admin sub-page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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