The same way you would in any other PHP program:
header("HTTP/1.1 401 Unauthorized");
exit;
WordPress has special handling for 404 because there’s a 404 template. Usually if something happens such as a 401, there is no special template, but you can make use of wp_die
which will show a message in a simple UI
header("HTTP/1.1 401 Unauthorized");
wp_die( 'forbidden' );
This will show the message in a white rectangle with rounded edges and sans-serif text on a gray background, then call exit
/die
Related Posts:
- Where to get information about array fields in $_REQUEST?
- Can I use HTTP POSTs? Is there a better alternative?
- Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
- Is there an equivalent to WP_Error object I can return in the case of a successful REST request?
- I am receiving a pluggable.php warning sign on my only http:// page
- Local WordPress with WAMP downloads files out of Nowhere
- Reading URL Parameters
- Display values of current POST request on page
- Sudden Upload HTTP errors, PHP uploads and memory limits are already to high to my taste. Anything else?
- Require advice handling a URL redirect from a Third Party. URL Params need to populate and then forward to payment
- My WP Website Shows HTTP ERROR 500
- Using the wp_remote_post response body
- Can i use php sql functions instead of $wpdb?
- Why include a composer.json file with my plugin?
- Customize default settings on new sites on multisite
- What is the best practice for escaping data URIs?
- Question about repurposing WordPress 404 handler
- append PHP function to the_content
- Setting up the child theme so as to enable right-to-left WordPress?
- How to track a users progress through pages by inserting data into WordPress Database?
- How do I get content of custom post type through post ID in wordpress
- Hooking new functions to actions + passing parameters
- How to display blog images using wordpress in existing project
- Block PHP Files Nginx
- Newbie question: no index.php? in my plain wordpress permalink
- enqueue hover function
- Theme Options: If There is No Input, Don’t Display?
- Proper use of internationalization
- Placing raw HTML inside a WordPress shortcode
- How to select WooCommerce products by post_meta and order them
- If search results empty then execute certain code
- An unwanted inline style is added to my body tag
- Recovering WP Login Credintials in Code?
- How to stop featured image thumbnail [set as background image] on blog index page just repeating same image across all posts
- Way to querry data (tags) from a wordpress database?
- Remove one value in dismissed_wp_pointers?
- wordpress count link clicks by ip address
- “comments.php” not available after edit in WP administration
- php script to change slug in post automatically
- Sort custom meta column by other meta value
- How to inject variables into public-facing JS using wp_enqueue_script
- Add more button if more 8 items
- check if comment submitted was successful
- Thumbnails appear to be zoomed
- “operation successful” message
- Conditional statement for dates
- Why does this update_post_meta function not delete the custom field itself?
- Location of core code for database connection and get_header
- Upload non-featured image to image field
- Change product_base programmatically
- Plugin development and composer
- WC_Customer delete function returns error
- Increment paged on WP_Query
- Some menu items wont budge
- Issue replacing forward slash in string
- Removing “Powered by” footer using child theme PHP [closed]
- custom post type with role Vendor
- Store and Change Session variable – PHP SESSION VARIABLE
- Show site content based on user role
- Cannot load media and I get “PHP Warning: Invalid argument supplied for foreach(“
- Adding “redirect” to a button
- PHP Parse error on WP-CLI, not on web server
- Get the id of the row from database on click of a button [closed]
- Trying to split a query into sections of six
- Execute Jquery when a specific page in my plugin is loading
- Modifying WP URL handing code?
- Show ranking based on post id
- Validating an email input from form field before submit using JQuery, AJAX, and PHP
- url not using query string no longer working
- How do I reopen the (Popup Maker) after entering the correct password for a password protected page?
- Display div if category has a specific parent
- Display metabox galleries on specific page template in admin editor
- I want it to detect the duplicate comment and give a warning on the same page
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- How to identify which php file a plugin is using on page load?
- dashboard widget form not submit mails
- Why am I getting syntax error, unexpected ‘endwhile’ (T_ENDWHILE) on single.php
- How to show category just on specific pages?
- Used a code to revoke some dashboard menus for my contributors but for some reason it’s revoked me access to the editor [closed]
- How do I get the value of a current user’s custom field?
- If is_page elseif is_page not working like I want it to
- Allow Comments by Default for Multiple Post Types
- HELP! Frontend User Profile Edit Won’t Update Email
- I want show only data for today
- Make customizer panel or section button
- Permalinks and custom PHP application
- Updating meta_value in a custom key
- Where to find the html for WordPress site? [closed]
- rewrite_rule – working fine but broken for pagination
- Custom post type single page return to listing page
- WordPress wp_remote_post() sending informaiton to Redmine REST API
- Using Nonce for my Form
- Transient Loop Not working as expected
- Shortcode working in page.php but not in category.php in wordpress
- Open all external links in new window – need help with the code
- ACF: Echo page title when checkbox is checked
- HTML in PHP problem [closed]
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Custom Post Type doesn’t have template content when creating programmatically in PHP but does when created in WP Admin
- How can add alt tag in following code. Image are showing dynamic in wordpress