Monday, July 5, 2021

Redirect wordpress author page to homepage

Dont' want to index default Wordpress author page to search engines and Google?

Redirect the author page from your theme to the homepage easily with this function.

add_action('template_redirect', 'my_custom_disable_author_page');

function my_custom_disable_author_page() {
    global $wp_query;

    if ( is_author() ) {
        // Redirect to homepage, set status to 301 permenant redirect. 
        // Function defaults to 302 temporary redirect. 
        wp_redirect(get_option('home'), 301); 
        exit; 
    }
}

Place this code to your theme functions.php file in the theme editor.

This works with Wordpress version 5.7.2 at least when I tried last time.


No comments: