Wordpress - Changing Admin Menu Labels
Here's the process to change the labels (I changed posts to "contacts" in my example)
function change_post_menu_label() {
global $menu;
global $submenu;
$menu[5][0] = 'Contacts';
$submenu['edit.php'][5][0] = 'Contacts';
$submenu['edit.php'][10][0] = 'Add Contacts';
$submenu['edit.php'][15][0] = 'Status'; // Change name for categories
$submenu['edit.php'][16][0] = 'Labels'; // Change name for tags
echo '';
}
function change_post_object_label() {
global $wp_post_types;
$labels = &$wp_post_types['post']->labels;
$labels->name = 'Contacts';
$labels->singular_name = 'Contact';
$labels->add_new = 'Add Contact';
$labels->add_new_item = 'Add Contact';
$labels->edit_item = 'Edit Contacts';
$labels->new_item = 'Contact';
$labels->view_item = 'View Contact';
$labels->search_items = 'Search Contacts';
$labels->not_found = 'No Contacts found';
$labels->not_found_in_trash = 'No Contacts found in Trash';
}
add_action( 'init', 'change_post_object_label' );
add_action( 'admin_menu', 'change_post_menu_label' );
To change the menu order, go with this:
// CUSTOMIZE ADMIN MENU ORDER
function custom_menu_order($menu_ord) {
if (!$menu_ord) return true;
return array(
'index.php', // this represents the dashboard link
'edit.php', //the posts tab
'upload.php', // the media manager
'edit.php?post_type=page', //the posts tab
);
}
add_filter('custom_menu_order', 'custom_menu_order');
add_filter('menu_order', 'custom_menu_order');
I've got code to remove items, but it's globally and not based on user access level
To rename default post type (or any other for that matter) just use filter post_type_labels_{$post_type}
. For default post
it will be post_type_labels_post
. In the code below is the full list of labels (WP 4.7.1
). You do not have to change everything.
add_filter( 'post_type_labels_post', 'news_rename_labels' );
/**
* Rename default post type to news
*
* @param object $labels
* @hooked post_type_labels_post
* @return object $labels
*/
function news_rename_labels( $labels )
{
# 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 = 'New News';
$labels->view_item = 'View News';
$labels->view_items = 'View News';
$labels->search_items = 'Search News';
$labels->not_found = 'No news found.';
$labels->not_found_in_trash = 'No news found in Trash.';
$labels->parent_item_colon = 'Parent news'; // Not for "post"
$labels->archives = 'News Archives';
$labels->attributes = 'News Attributes';
$labels->insert_into_item = 'Insert into news';
$labels->uploaded_to_this_item = 'Uploaded to this news';
$labels->featured_image = 'Featured Image';
$labels->set_featured_image = 'Set featured image';
$labels->remove_featured_image = 'Remove featured image';
$labels->use_featured_image = 'Use as featured image';
$labels->filter_items_list = 'Filter news list';
$labels->items_list_navigation = 'News list navigation';
$labels->items_list = 'News list';
# Menu
$labels->menu_name = 'News';
$labels->all_items = 'All News';
$labels->name_admin_bar = 'News';
return $labels;
}
If you want internationalization support, just use __( $text, $textdomain )
like:
$labels->name = __( 'News', 'textdomain' );
I found the filter in function: get_post_type_labels()
from a file wp-includes/post.php
:
/**
* Filter the labels of a specific post type.
*
* The dynamic portion of the hook name, `$post_type`, refers to
* the post type slug.
*
* @since 3.5.0
*
* @see get_post_type_labels() for the full list of labels.
*
* @param object $labels Object with labels for the post type as member variables.
*/
$labels = apply_filters( "post_type_labels_{$post_type}", $labels );
I agree.. The functions.php
file gives lots of flexibility. I've needed some of the same functionality that you described with a combination of functions.php
filters and this plugin.
From what I can tell..this plugin would accomplish both of your issues and it works well in Multi-Site install situations too. Hope that helps.