How to Remove Author from WordPress Posts: A Beginner’s Guide

Home » Snippets » How to Remove Author from WordPress Posts: A Beginner’s Guide
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

If you run a multi-author WordPress blog or website, you might want to remove the author’s name from some posts to maintain consistency or make the content more anonymous. While WordPress doesn’t offer a built-in option to remove author names, there are a few simple ways to do it yourself. In this article, we’ll show you how to easily remove the author’s name from posts in WordPress.

					function wpturbo_remove_post_author( $defaults ) {
    if ( isset( $defaults['author'] ) ) {
        unset( $defaults['author'] );
    }
    return $defaults;
}
add_filter( 'manage_posts_columns', 'wpturbo_remove_post_author' );

function wpturbo_remove_author_from_post( $column_name, $post_id ) {
    if ( $column_name === 'author' ) {
        echo 'N/A';
    } 
}
add_action( 'manage_posts_custom_column', 'wpturbo_remove_author_from_post', 10, 2 );
				

In WordPress, each post has an author assigned to it by default. However, there are times when you may want to remove the author’s name from your posts. This could be because you are using WordPress as a CMS and the author’s name is not relevant, or it could be because you have multiple authors and you don’t want to display their names on the posts.

The code snippet above provides a solution to remove the author’s name from all posts in WordPress. Let’s take a closer look at how it works.

The first function wpturbo_remove_post_author() is a filter that removes the author column from the posts listing page. This is done by modifying the default columns array and unsetting the author key.

function wpturbo_remove_post_author( $defaults ) {
    if ( isset( $defaults['author'] ) ) {
        unset( $defaults['author'] );
    }
    return $defaults;
}

By using manage_posts_columns hook, we can manipulate the displayed columns. This code first checks if the author index exists in the $defaults array, and removes it if it does.

The second function wpturbo_remove_author_from_post() is an action that replaces the author’s name with ‘N/A’ on the posts listing page. This is done by checking if the column being rendered is the author column and simply outputting ‘N/A’ instead of the author’s name.

function wpturbo_remove_author_from_post( $column_name, $post_id ) {
    if ( $column_name === 'author' ) {
        echo 'N/A';
    } 
}

We use the manage_posts_custom_column hook to achieve this job. It accepts two parameters: the column name and the post ID. We only want to manipulate the output if the column name is ‘author’, so we check if $column_name is equal to ‘author’. If it is, we use echo to output ‘N/A’ in place of the author name.

By combining these functions, we can remove the author’s name from all posts in WordPress.

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