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
- How exactly do automatic updates work?
- How to create custom 401, 403 and 500 error pages?
- Why have on every line
- What is in media-template.php, and how does it work?
- add_action in namespace not working
- How to add a .php file to WordPress
- When to use Exceptions vs Error Objects vs just plain false/null
- Query both first_name and last_name from wp_usermeta at the same time
- Woocommerce get selected shipping zone id for the current user
- Is it possible to disable a function of a parent theme?
- Variables declared in header not available in other includes
- Hide old attachments from wp media library
- Image Upload “exceeds the maximum upload size for this site”, but php.ini is correct
- PHP – redirect https to http and www to non-www
- Create Image Uploader for Widget
- WordPress Ajax always returns a 404 error
- Woocommerce -How to set product regular price default
- Displaying a variable stored in functions.php inside widget
- Custom Meta Field – Youtube embed
- Action ‘save_post’ not working for quick edit
- simple wordpress ajax plugin not working when not logged in
- Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied
- Add to previous posts under post
- Failed to open stream / no such file or directory
- Customizer Show/Hide Logo and Site Title
- Notice: Constant already defined in wp-config.php on (non-existent) line?
- Need to get specific data from array
- Use different javascript files for each page on website
- body_class filter – Is there a better way to write this code?
- Limiting the WordPress feed to only a certain limit of characters
- Mail not sent when I set HTML headers
- Categories Template Assistance
- How to get all existing post types
- How to get Poster (thumbnail) Image of Video
- Why Better WP security plugin returns 418 I’m a Teapot “error”?
- Include a specific post to the query_posts and remove it if it is already in the returned list
- Fatal error: Call to undefined method WP_Error::get_item_quantity()
- javaScript in section of WP API
- When would you use $_post instead of $post?
- Autogenerate shortcodes from an array of strings
- Remove annoying WP Adminbar CSS
- API response to be stored locally
- How to convert objects into arrays
- PHP code to call image Caption, Alternative Text, and Decription?
- Removing unneccessary p-tags (Not every p)
- Integrate WordPress in Yii
- wp_kses and magic quotes
- Customize Plugin
- How to implement Google Tag Manager? [closed]
- How to rewrite URL with PHP variables with htaccess to a normal looking URL?
- Huge debug.log because of “undefined offset in media.php”
- display month in french in wordpress/php?
- Retrieving Author ID in wp-admin area
- Custom Theme, Custom shortcode not working
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Can’t get wp_insert_post to work
- Why not yield/iterable in posts interface?
- Part of title duplicating but not sure how to remove from code – help?
- Create a hierarchical taxonomy list in WordPress
- Randomly Assign an Image’s Alt Text Based on Data From Post
- Adding custom directory and PHP files in wordpress
- How to: PHP Log Out Link?
- How can I Add a variable PHP in the Menu Nav
- Pull the content out of a page
- 200 Rewrite blog post links
- PHP Fatal error: Uncaught mysqli_sql_exception: Table doesn’t exist in wordpress/wp-includes/wp-db.php
- Adding an Avatar to the Top Nav Bar
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Edit incorrect password message WordPress
- wp search-replace on database returns PHP fatal error: Array and string offset access syntax with curly braces is no longer supported
- Best way to add more options to Gutenberg “More Rich” text controls drop down
- code is skipping a div
- Avoid parallax images hardcoding
- The response is not a valid JSON response, wordpress problems?
- Firing schema via code in functions.php doesn’t work
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- XAMPP-VM Mac OS Mojave wordpress debugging using XDebug
- How to get original custom taxonomy slug after the slug has been rewritten?
- WordPress Persistent connection rule does not work for “posts”
- How to use wp_add_inline_style for custom CSS added via shortcode?
- Blog posts repeat
- Ajax load more button for comments wordpress
- WordPress & Fastcgi proper setup?
- Options API get_option() and update_option() Not Correctly Updating or Returning
- Unique icons next to each WordPress menu item
- Dot is not added at the end of href
- Update user profile information from functions.php
- Getting error when using wp_insert_post()