Title

PHP Custom post alt: Change post and taxonomy labels

description

Induce custom post behavior with the default WP posts by changing the labels. Combine with ACF to create more custom post behavior.

Published 2022-05-09

Modified 2022-08-19

content

				
					// Change Labels 'Posts' to 'News' in Dashboard

function rp_change_post_object() {
    $get_post_type = get_post_type_object('post');
    $labels = $get_post_type->labels;
        $labels->name = 'News';
        $labels->singular_name = 'News';
        $labels->add_new = 'Add News';
        $labels->add_new_item = 'Add News';
        $labels->edit_item = 'Edit News';
        $labels->new_item = 'News';
        $labels->view_item = 'View News';
        $labels->search_items = 'Search News';
        $labels->not_found = 'No News found';
        $labels->not_found_in_trash = 'No News found in Trash';
        $labels->all_items = 'All News';
        $labels->menu_name = 'News';
        $labels->name_admin_bar = 'News';
}

add_action( 'init', 'rp_change_post_object' );
				
			
				
					// Change Category Labels

function rp_change_cat_label() {
    global $submenu;
    $submenu['edit.php'][15][0] = 'Theme'; // New Dashboard label for 'Category'
}
add_action( 'admin_menu', 'rp_change_cat_label' );

function rp_change_cat_object() {
    global $wp_taxonomies;
    $labels = &$wp_taxonomies['category']->labels;
    $labels->name = 'Themes';
    $labels->singular_name = 'Theme';
    $labels->add_new = 'Add Theme';
    $labels->add_new_item = 'Add Theme';
    $labels->edit_item = 'Edit Theme';
    $labels->view_item = 'View Theme';
    $labels->search_items = 'Search Theme';
    $labels->not_found = 'No Theme found';
    $labels->not_found_in_trash = 'No Theme found in Trash';
    $labels->all_items = 'All Theme';
    $labels->menu_name = 'Theme';
    $labels->name_admin_bar = 'Theme';
}
add_action( 'init', 'rp_change_cat_object' );
				
			
				
					// Change Tag Labels

function rp_change_tag_label() {
    global $submenu;
    $submenu['edit.php'][16][0] = 'Topic'; // New Dashboard label for 'Tags'
}
add_action( 'admin_menu', 'rp_change_tag_label' );

function rp_change_tag_object() {
    global $wp_taxonomies;
    $labels = &$wp_taxonomies['post_tag']->labels;
    $labels->name = 'Topics';
    $labels->singular_name = 'Topic';
    $labels->add_new = 'Add Topic';
    $labels->add_new_item = 'Add Topic';
    $labels->edit_item = 'Edit Topic';
    $labels->view_item = 'View Topic';
    $labels->search_items = 'Search Topic';
    $labels->not_found = 'No Topic found';
    $labels->not_found_in_trash = 'No Topic found in Trash';
    $labels->all_items = 'All Topics';
    $labels->menu_name = 'Topic';
    $labels->name_admin_bar = 'Topic';
}
add_action( 'init', 'rp_change_tag_object' );