Skip to content

Instantly share code, notes, and snippets.

@deadlyhifi
Last active November 22, 2018 11:54
Show Gist options
  • Save deadlyhifi/5245200 to your computer and use it in GitHub Desktop.
Save deadlyhifi/5245200 to your computer and use it in GitHub Desktop.
WordPress: Rename Posts in admin menu.
/**
* Rename Posts in admin menu
*
*/
new dhf_rename_posts('News');
class dhf_rename_posts
{
private $name;
public function __construct($name)
{
$this->name = $name;
add_action('admin_menu', array($this, 'change_post_menu_label'));
add_action('init', array($this, 'change_post_object_label'));
}
public function change_post_menu_label()
{
global $menu, $submenu;
$menu[5][0] = $this->name;
$submenu['edit.php'][5][0] = $this->name;
$submenu['edit.php'][10][0] = 'Add ' . $this->name;
}
public function change_post_object_label()
{
global $wp_post_types;
$labels = $wp_post_types['post']->labels;
$labels->name = $this->name;
$labels->singular_name = $this->name;
$labels->add_new = 'Add ' . $this->name;
$labels->add_new_item = 'Add ' . $this->name;
$labels->edit_item = 'Edit ' . $this->name;
$labels->new_item = $this->name;
$labels->view_item = 'View ' . $this->name;
$labels->search_items = 'Search ' . $this->name;
$labels->not_found = 'No ' . $this->name . ' found';
$labels->not_found_in_trash = 'No ' . $this->name . ' found in Trash';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment