Code snippet to block author pages

So you can remove the author-pages with an author.php file in your (child) theme, but what if you don’t want to touch the theme you ask? Well, I just added this code snippet to two of the sites I manage to stop user-enumeration (which can be done on any WordPress site by going to /index.php?author=1):

add_action('wp','no_author_page'); function no_author_page() { if (is_author()) { global $wp_query; $wp_query->set_404(); status_header( 404 ); get_template_part( 404 ); exit(); } }

Disclaimer: the bulk of above code was shamelessly copy/ pasted from

1 thought on “Code snippet to block author pages

  1. Jeff Mcneill

    To remove links to author pages, as well as author pages:

    // Remove Author Pages and Links
    function remove_author_pages_page() {
    if ( is_author() ) {
    global $wp_query;
    status_header( 404 );
    function remove_author_pages_link( $content ) {
    return get_option( ‘home’ );
    add_action( ‘template_redirect’, ‘remove_author_pages_page’ );
    add_filter( ‘author_link’, ‘remove_author_pages_link’ );
    // End Remove Author Pages and Links

Leave a Reply to Jeff McneillCancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.