Those variables and functions only exist in the admin area, and aren’t for frontend use. You will need to use a different mechanism for the frontend.
Additionally:
- the docs say that you have to call this after the
admin_init
hook, calling on that hook will always returnnull
- the function is not loaded on all admin pages, e.g. the customizer
- Use it on the
current_screen
hook or later
When in doubt, read the documentation
Related Posts:
- How to catch/what to do with a WP Error Object
- What are the best practices for updating?
- Is there a plugin that will override the “Error establishing a database connection” message? [closed]
- Loading external page template and enqueue script from plugin causes 403 forbidden error
- Where can I find a schema of wordpress plugin core architecture?
- How to Loop Plugin Option Field Set?
- PHP Deprecated: Non-static method should not be called statically
- Save and retrieve custom plugin options value
- Using tabs for wordpress plugin
- How to handel multiple checkbox field in the admin settings page with Settings API
- Custom plugin settings: clicking “save changes” does not display success message
- How can I include a setting that has a variable number of values in a settings page using register_setting?
- Plugins error (Use roles and capabilities instead) on latest version, multisite
- WordPress error – PHP Fatal error: Uncaught Error: Call to undefined function register_block_type_from_metadata()
- “Are you sure you want to do this?” when deactivating all plugins in WordPress 4.3.1 [closed]
- How should I handle errors within a plugin?
- An Unexpected HTTP Error occurred during the API request
- Plugin set default setting value when it activated
- Get page slug in Admin menu
- Add a Custom Permalink option in the Permalink Admin Screen?
- Seaweed Plugin not working
- All plugins deactivated due to error
- Wp die causing 500 Internal Server Error?
- Unable to activate wordpress importer after installing it
- Weird problems after recovery from security breach
- Error in the wp-config.php file: PHP Fatal error: Uncaught Error: Unknown named parameter (PHP 8.0)
- Can a plugin still effect a site even after deletion?
- Error handling a plugin with exceptions
- Post-terms-order PHP errors after update
- Call to undefined function get_userdata in user.php
- Only Homepage not loading properly
- One of my plugins broke when I tried to update it, how do I safely uninstall it?
- Images not showing after changing wp-content folder name
- WooCommerce Checkout Error [closed]
- Plugin: Google Analytics for Dashboard error – Timestamp is too far from current time
- How to redirect a URL with parameters?
- Problem using Press-this book marklet
- Most efficient way to use classes to create admin pages using Settings API
- Show admin notice on incorrect value on form field
- Deactivating all plugins and reactivating one by one, fixes conflicts. Why?
- Cannot display settings field
- Checkbox conflict in my custom plugin admin page
- Unable to get WP_DEBUG, WP_DEBUG_DISPLAY, WP_DEBUG_LOG to work
- Get errors from WP_Error to different variables
- help with my wordpress website
- HTTP 500 error after plugin install
- Can’t activate Plugin: unexpected T_STRING, expecting T_FUNCTION [closed]
- Plugin getting Cannot modify header information errors
- WP-nivo-slider Producing Error “Cannot modify header information – headers already sent by …”
- XML Sitemap Generator can’t notify google and bing
- After updating the WordPress getting a syntax error in the console
- There has been a critical error on your website – won’t fix no matter what
- Update WP option by plugin
- Plugin showing error
- Classic, but puzzling “The uploaded file could not be moved”
- Plugin upgrade failing during unzip
- Problem after updating plugins
- Settings API Message Error is global
- Apparent errer when installing plugin
- How to get Facebook comment plugin in blog? [closed]
- Undefined index: ratings_score …/wp-postratings.php on line 994
- Strange Behavior on New Theme Points to Idiocy
- 404 errors when updating options in admin dashboard
- Error activating certain plugins
- All new plugins generating 311 chars of unexpected output?
- How to make sure settings are not lost when plugin is updated?
- Error when adding extensions to wordpress version 5.9 with a DIVI install
- Replace old theme that understand old css (vcex_icon_box css_animation)
- There has been a critical error on this website
- WP search box on page not finding .PDF files
- How to Fix WordPress multisite woocommerce 403 file error
- Critical Error after Updraft Restoration
- There has been a critical error on your website
- Modifying server’s response to API endpoint
- Woocommerce functions in custom class, avoid errors
- ERROR message: “The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.”
- Object of class WP_Error could not be converted to string in /formatting.php
- How do I render content from a wp_editor in a plugin setting field?
- Settings Fields not showing up in Submenu Page
- Error after installing the WordPress plugin updates
- White blank screen while adding or editing pages in wordpress
- Cannot modify header information – headers already sent during plugin activation
- WordPress error after installing plugin “Internal Server Error” [closed]
- Need Help Understanding Debug Log Errors
- Plugin debugging with errors in activation routine
- WP default file upload hook not working if used in a plugin
- Option page not updating multiple records in settings api
- Validating values using Settings API?
- A plugin is giving me “You do not have sufficient permissions to access this page.” error
- Restore Category Base
- Plugin (smart archives reloaded) crashed site / no access on admin panel
- Custom Post type plugin breaking the front page shows dashboard?
- Plugin won’t activate, fatal error (widget class not found)
- Plug-in (Slickr Flickr) works on local machine, but not server
- How can I save a setting field with multiple checkbox options generated by a foreach loop on a custom wordpress admin page?
- Theme causing SSL break on chrome
- WordPress Customer Reviews Error: Line 239?
- WordPress Plugins Error
- How to get an error message if a form is empty (plugin: Post for site) [closed]
- Oxygen plugin wordpress stuck in loading sequence forever when trying to edit a page [closed]