Created
January 3, 2015 12:34
-
-
Save ibrokemywp/8aae30cc495d4ae7e842 to your computer and use it in GitHub Desktop.
Two ways to enqueue an asset on an admin sub-page when it has been translated.
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
/** | |
* Use the `$admin_page_hook[ $page_slug ]` in the `load-{page}` hook | |
*/ | |
global $admin_page_hooks; | |
if ( !empty( $admin_page_hooks['myplugin-parent'] ) ) { | |
add_action( 'load-' . $admin_page_hooks['myplugin-parent'] . '_page_myplugin-subpage', 'enqueue_myplugin_assets' ); | |
} | |
/** | |
* Or add `$admin_page_hook[ $page_slug ]` when checking the current | |
* screen. | |
*/ | |
add_action( 'admin_enqueue_scripts', 'enqueue_myplugin_assets' ); | |
function enqueue_myplugin_assets() { | |
global $admin_page_hooks; | |
$screen = get_current_screen(); | |
if ( !empty( $screen ) && !empty( $admin_page_hooks['myplugin-parent'] ) && $screen->base == $admin_page_hooks['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