Snippet to disable Author archives

Home » Snippets » Snippet to disable Author archives

Created with:



Creator: Ahrale

Customize with WPTurbo AI

Add Snippet To Project

New Project
Add To Existing Project
// Disable author archives
function disable_author_archives() {
    if (is_author()) {
        global $wp_query;
add_action('template_redirect', 'disable_author_archives');


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.

Register an account to save your snippets or go Pro to get more features.