When creating a new custom post type in WordPress, we can define the labels however we like, such as “Products” or “Downloads”. Sometimes, however, we need to rename the built-in Posts labels as well to fit a specific requirement. There is more than one way to achieve that.
Method 1: Filter the translated strings
This method works by filtering translated strings when WordPress loads the translation files, replacing the word for Posts with News. The code looks like this:
// Hook into translation filters
add_filter('gettext', 'change_post_to_news');
add_filter('ngettext', 'change_post_to_news');
function change_post_to_news( $translated ){
$translated = str_ireplace( '文章', '新闻', $translated );
return $translated;
}
Method 2: Change the menu labels directly
This method uses the WordPress admin_menu hook to replace the labels shown in the admin menu.
function wizhi_posts_news() {
global $menu;
global $submenu;
$menu[5][0] = __("新闻", 'litho');
$submenu['edit.php'][5][0] = __("新闻", 'litho');
$submenu['edit.php'][10][0] = __("发新闻", 'litho');
echo '';
}
add_action( 'init', 'wizhi_posts_news' );
add_action( 'admin_menu', 'wizhi_posts_news' );
Both methods work well, and neither one requires you to edit the translation files directly. That said, unless there is a real need to do so, I still recommend leaving the default WordPress Posts label alone, because renaming it may confuse some less experienced users.
