The function add_menu_page
return the hook suffix that inform you about the current page.
A simple example to get the hook suffix.
public function add_menu_page() {
$page_hook_suffix = add_menu_page(
esc_html__( 'Admin Page', 'translation-slug' ),
esc_html__( 'Admin Page', 'translation-slug' ),
'read',
'My Name',
array( $this, 'get_styles' )
);
add_action( 'admin_print_scripts-' . $page_hook_suffix, array( $this, 'enqueue_assets' ) );
}
The example above add the scripts only on the custom admin page, because the hook admin_print_scripts-*
is fired only on the hook suffix from the return value of add_menu_page
.
WP_Screen
Also, you can use the function get_current_screen
to identify the page and use the value after identification.
Helpers
There are also helper plugins to find this value, if is not dynamically, like Query Monitor and Debug Objects.
Screenshot
Related Posts:
- Seriously stuck with some custom meta box/plugin stuff
- Admin Dashboard with Custom Tab for Client
- Inserting Plugins Into Blank Space of Externally Designed WordPress Theme
- How to Call Specific .PHP file on add_submenu_page selection in Plugin Development?
- CMB2 Output Select Box Chosen Option
- How can I remove this sidebar from my Search Results page?
- Metabox Data not saving
- Meta Box plugin image_advanced not showing up on frontend
- How to build an API as a plugin
- category_name not working (not showing up in sql query debug)
- How can I make my custom shortcode work in a Custom HTML Widget?
- Update Multiple Post Meta for the Same Post In One call?
- WordPress Hook that will run when media file deleted
- How do I configure WordPress to talk to a Microsoft SQL Server database?
- Post source link plugin – small modification
- Which hook callback has priority if both plugin and theme use the same hook?
- Creating Custom Meta Boxes on Plugin Option Page
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- How can I make the “Preview Post” button save and preview in the same window?
- Escape special characters in image link
- Cannot run the code after I activate the plugin
- Displaying admin notice dynamically
- Calling a plugin in theme development
- Unable to activate wordpress importer after installing it
- Get total number of comment of the posts written by an author
- WordPress Ajax Callback
- printf – problem to understand code
- Auto delete WordPress users according to time
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- add_query_arg not working
- add_menu_page does not seem to work in a class
- Theme my Login plugin, how to update fields
- How would I go about creating a user ranked post popularity page?
- All of my custom posttypes are 404’ing
- WordPress: PHP code rendering in the wrong place
- New to wordpress, Question about editing PHP
- PHP basics help in WP context – remove a class/function?
- How to edit content before post update
- Customize permalink wordpress category id
- Take input from form and pass it to function using a wp-plugin
- Show meta box only when post is being published first time
- Why is one phpunit test throwing an error on one class when all other classes are similar without error?
- WordPress call_user_func_array() expects parameter 1 to be a valid callback, class
- How to add apply_filter for a class property in plugin
- Warning: Use of undefined constant list_all – assumed ‘list_all’ (this will throw an Error in a future version of PHP)
- A server-side hook failed when committing plugin code to SVN
- Content-Security-Policy Headers are there and showing the correct settings, but still getting a refused connection
- Need to replace Currency Shortforms
- Api external with wordpress
- How to delete all categories programatically?
- How to use custom Javascript code inside a plugin?
- How to use printf to output two links?
- Using meta_query in a WP_Query not working for numbers properly
- File Uploader – Upload without adding to Media Library
- Adding submenu to custom plugin menu page created with add_menu_page() function
- Building a plugin into a theme
- 2 wordpress site same database
- Trying to include files in plugin isn’t working
- How to makes changes on the shop/category/tag pages but not on the product pages in woocommerce?
- implement custom roles in custom plugin
- How to get current cart values using WC_Shortcodes?
- How to authorize viewing and clicking a function only logged users?
- WordPress is redirecting me to homepage
- How can we get this dynamically as this folder may not be by the same name always → wp-admin
- Cant create table on plugin activation
- How to arrange custom posts in the backend/admin by custom taxonomy
- WordPress default post categories meta box widget
- How to ignore fields if empty?
- Why is my shortcode not working?
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- Moving a few select DB tables to a new WP instance
- implement checkbox or toggle switch in plugin code
- Custom Field used to allow a Free Story; no longer works
- How to send new visitor to a splash page for only one time in wordpress?
- How to get the total count of Favorite/Favorited authors
- Admin login substantially slower on production server
- redirect to a custom page
- My own metabox checkbox plugin only saves the last value I’ve checked
- GET web api method from a WordPress PHP script
- How to change text in a page by utilizing a custom user id?
- Adding link on title its in description but not in title see screenshots attached
- How can I insert a record into a custom table from my custom form in my custom admin page?
- How to save information related to post in database?
- Save selectlist value (taxonomy) in wp:wp_set_object_terms
- Page doesn’t load
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Xml output not places where i want
- Including a PHP file via a function that is part of a plugin?
- How do I output user_registered time in my correct timezone?
- How to fix ‘Call to undefined function do_settings()’ error?
- Integrate Razorpay quick payments plugin with contact form7 plugin
- Translate text for empty product
- Passing an input variable through a switch statement
- How to add custom html to the Media > Attachment Details modal?
- add_meta_box showing blank screen in my page
- Option value not getting updated until page refresh in WordPress
- Fatal error: Uncaught Error: Call to a member function fetch_array() on bool
- I want create woocommerec match products columns
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class