Home / Archive / Disable Author Archive
Duplicate Snippet

Embed Snippet on Your Site

Disable Author Archive

A small Code that disable the WordPress Author Archive and redirect to the Homepage

Code Preview
php
<?php
/* Get Statuscode 404 for existing & non-existing author archives. */
add_action( 'template_redirect',
	function() {
		if ( isset( $_GET['author'] ) || is_author() ) {
			global $wp_query;
			$wp_query->set_404();
			status_header( 404 );
			nocache_headers();
		}
	}, 1 );
/* Remove the Author Links */
add_filter( 'user_row_actions',
	function( $actions ) {
		if ( isset( $actions['view'] ) )
			unset( $actions['view'] );
		return $actions;
	}, PHP_INT_MAX, 2 );
add_filter( 'author_link', function() { return '#'; }, PHP_INT_MAX );
add_filter( 'the_author_posts_link', '__return_empty_string', PHP_INT_MAX );

Comments

Add a Comment