0
X
Add Snippet To Project
New Project
Add To Existing Project
<?php
// Disable author archives
function disable_author_archives() {
if (is_author()) {
global $wp_query;
$wp_query->set_404();
status_header(404);
nocache_headers();
}
}
add_action('template_redirect', 'disable_author_archives');
Explanation:
This code adds a custom function disable_author_archives that checks if the current page is an author archive using the is_author() function. If it is, it sets the query to return a 404 page using $wp_query->set_404(), sets the status header to 404 using status_header(404), and disables caching using nocache_headers().
The add_action('template_redirect', 'disable_author_archives') line hooks the disable_author_archives function to the template_redirect action, which is fired before the template is loaded.
By adding this code to your theme's functions.php file, author archives will be disabled and return a 404 error page.