Setting a 404 in WordPress can be done quite easily using the set_404()
method of WP_Query
and the status_header()
function. Here’s an example taken from WP::handle_404()
:
$wp_query->set_404();
status_header( 404 );
nocache_headers();
If I wanted my tag archive to be accessible to authenticated users only, setting a 404 page for non-authenticated users wouldn’t make sense because the resource does exist, it’s just not available to logged-out users.
My question
How would I set a 401 in WordPress?