Skip to content

Instantly share code, notes, and snippets.

@raaar
Last active April 7, 2022 13:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save raaar/9206302 to your computer and use it in GitHub Desktop.
Save raaar/9206302 to your computer and use it in GitHub Desktop.
WORDPRESS: change Posts label in admin area
function change_post_label() {
global $menu;
global $submenu;
$menu[5][0] = 'News';
$submenu['edit.php'][5][0] = 'News';
$submenu['edit.php'][10][0] = 'Add News';
$submenu['edit.php'][16][0] = 'News Tags';
echo '';
}
function change_post_object() {
global $wp_post_types;
$labels = &$wp_post_types['post']->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( 'admin_menu', 'change_post_label' );
add_action( 'init', 'change_post_object' );
@clescuyer
Copy link

Interesting, thank you. For the labels, you could also do it with a filter:

// This is defined in a class
add_filter( 'post_type_labels_post', array( $this, 'change_post_labels' ) );

function change_post_labels( $args )
{
	$args->name = 'News';

    	return $args;
}

The filter can be called on specific post_types, its name is post_type_labels_{$post_type}.
I believe the function might be called less often than if you hook it on init.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment