Open (Re)source

Change ‘Posts’ name to something else

By

Sometimes you want to change the WordPress posts to something else. Here’s how you can do it.

Arrow pointing at Posts in WordPress dashboard navigation
Before: WordPress native ‘Posts’

Today, I’ll change ‘Posts’ to ‘Books’. I want Books to appear where the label ‘Posts’ are regardless of what theme is installed. So I’ll make my changes in my custom plugin. 

Arrow pointing at Books in WordPress dashboard navigation
After: WordPress native ‘Posts’ is structurally identical, but is now called “Books”

We’re going to use this function to find the ‘Post’ object by name, and change it: get_post_type_object.We’re referencing the ‘post’ object in the function get_post_type_object and we’re putting that in a variable called $get_post_type. Then we’re going to put $get_post_type in a variable called $labels to access labels property. In the code below replace “Books” and “Book” with what you want it to be named.

// Change "Posts" to "Books"

add_action( 'init', 'change_post_object' );

// Change dashboard Posts to Books

function change_post_object() {

    $get_post_type = get_post_type_object('post');

    $labels = $get_post_type->labels;

        $labels->name = 'Books';

        $labels->singular_name = 'Book';

        $labels->add_new = 'Add Book';

        $labels->add_new_item = 'Add Book';

        $labels->edit_item = 'Edit Book';

        $labels->new_item = 'Book';

        $labels->view_item = 'View Book';

        $labels->search_items = 'Search Books';

        $labels->not_found = 'No Books found';

        $labels->not_found_in_trash = 'No Books found in Trash';

        $labels->all_items = 'All Books';

        $labels->menu_name = 'Books';

        $labels->name_admin_bar = 'Books';

        $get_post_type->menu_icon = 'dashicons-book'; //Change the dashicon icon

}

Original code from: https://wpbeaches.com/change-the-wordpress-post-type-name-to-something-else/

Leave a Reply

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