Working in the admin is quite a bit different from the front-end of a WordPress site. Most of the documentation you’ll find online deals solely with the front-end. That can be frustrating when looking for something that should be simple and straightforward.
In this case, I think you would use get_current_screen(). This returns the screen’s ID, action, base, and other features of the admin page.
From the codex on get_current_screen():
This function returns an object that includes the screen’s ID, base,
post type, and taxonomy, among other data points
This doesn’t work everywhere in the admin, so make sure you read the restrictions.
Related Posts:
- How to get URL of current page displayed?
- Dynamic URL to reference custom PHP files
- How is WordPress manipulating the posts like there are folders?
- Extend PHP regex to cover “srcset” and “style” attributes
- Create custom permalinks to show Custom Post Type’s relationship?
- Change product_base programmatically
- WordPress permalink issue
- Allow two posts (from different categories) to have the same slug
- Rewrite rule not working, but only when parameter is text
- Get WordPress username to customize url
- WordPress/NGINX not respecting the category URL for new posts
- How does one make a URL return dynamic JSON with custom Content Type?
- How do I generate formatted permalinks as specified in backend options?
- Remove /category/ from category (archive) page URLs (without using a plugin)
- How to extract URLs from wordpress taxonomies
- Create a custom plugin with dynamic child pages listing database records
- Remove slug of multiple custom post types with and without hierarchical
- Custom plugin with dynamic child pages listing database records
- I can’t fetch query parameters ($_GET parameters) with get_query_var
- how to get permalink structure with php
- Change Password Hint
- Prevent multiple counts by same user – WP PostViews plugin
- Second select list values are not saved after clicking update
- Use wc_enqueue_js only on specific pages – nested add_action
- Theme url in all plugin pages
- Put a link to a category round a hard coded A HREF
- Newbie question: no index.php? in my plain wordpress permalink
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- wordpress upgrade has broken my permalinks
- How to access function from outside of a class within this class in WP plugin?
- How can i display post loop in table format?
- PHP can I add line numbers to file_get_contents()
- Add prefix to link url
- php script to change slug in post automatically
- what is the best practice to add new field to an api route
- Use custom post type for a store locator
- Colon is Missing In My Website Url in WordPress
- How do I programmatically set a user as spam in BuddyPress? [closed]
- How to make my custom widget appear within WordPress widgets? Plugin development
- Adding widgets to my plugin page instead of WordPress dashboard
- How to insert data into database using wp cron job
- Access Child Class of Plugin Main Class Instance
- Font Awesome changing default WordPress Font
- Download full html page with CSV export plugin
- Usage of call back function of add_meta_box()
- how to save checkbox data for custom setting?
- How to Schedule Cronjobs for start of every month and year
- I’m unable to call img path using single quotes in an array?
- Need to Modify a WordPress Shortcode with another wordpress shortcode
- WordPress WP_Query without query GET parameters
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- Removed jQuery script from header.php , any problems?
- How can I get plugin meta data without knowing the plugin folder?
- Adding custom url to readmore link using get_permalink()
- How to set base url for php widget
- Permalinks: site.com/post-tite vs site.com/post-id/post-title for SEO and Speed
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- How does add_option() function enable action hooks to fire right after actiavtion?
- Change permalink structure specific category
- Custom URL for multiple categories hierarchy
- Create plugin with custom page and template caused an error `Call to undefined function get_header()`
- WordPress redirects to localhost
- Unable to display multiple parameters from url by javascript through shortcodes
- Settings API form – submit with AJAX
- Submit remote form to wordpress REST API and save data to custom post type
- Foreach Loop Of Post Types With Nested If Else If Not Completing Process
- In a foreach loop, how can I add a meta value if it doesn’t exist?
- Looping through and combining calls to Woocommerce REST API
- Should I use wp_cache in my plugin to make it faster?
- How to import woocommerce custom fields data into another site?
- Permalink doesn’t navigate to post (changes only url)
- Add a custom link to each image in WordPress gallery
- When I create a new custom post type, it replaces the old post type
- How do I stop my form from adding code to current page URL instead of re-directing. Been stuck for days
- image on homepage disappeared due to change of permalink name
- Add .php to end of all WordPress Pages (multisite)
- Getting Member Data From WhishList Member on Register
- Some links broken after updating WordPress version
- global $post inside plugin query messes up every new post page in wp-admin
- wp_query (or hook) posts by date (id) in array then set post_type
- Chosen Select jquery Not Working in Plugin
- PHP calling function within a class
- Save data of select list after clicking save
- Magento and WordPress URL integration [closed]
- Can’t remove menu items added by plugin
- How to remove parent section in an attachment URL in wordpress?
- Issues separating my Plugin pages into different files
- How to hide Ads From Certain Categories?
- Custom field fetch error on woocommerce pdf invoice
- How to pass and validate nonce in custom REST routes
- why css file not link?how to create permalink?
- ajax problems on loading page [closed]
- wp_mail – send emails after 24 hours from users registration
- Compare user meta values before update them
- Capture the Selected Radio Button Value between two files in wordpress theme
- How to change product SKU’s in bulk with a plugin
- JQuery UI Autocomplete showing as bullets
- Modify the permalink structure for a specific category
- Remove links to the comments section
- Add Imports to Existing WordPress Import Map