Skip to content

Instantly share code, notes, and snippets.

@gyrus
Created July 21, 2012 14:40
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save gyrus/3155982 to your computer and use it in GitHub Desktop.
Save gyrus/3155982 to your computer and use it in GitHub Desktop.
Rename WordPress "Posts" to "News"
<?php
/**
* Rename "Posts" to "News"
*
* @link http://new2wp.com/snippet/change-wordpress-posts-post-type-news/
*/
add_action( 'admin_menu', 'pilau_change_post_menu_label' );
add_action( 'init', 'pilau_change_post_object_label' );
function pilau_change_post_menu_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 pilau_change_post_object_label() {
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';
}
@bavington
Copy link

Awesome Gist, works perfectly. P.S Steve the link within the code is broken.

@joeforshaw
Copy link

Awesome, thank you!

Something to note, I ran into an issue where if the current user went to their dashboard but didn't have permission to view/edit posts, it would crap out and give:

Notice: Undefined offset: 2 in /srv/www/wordpress-default/wp-admin/includes/plugin.php on line 1573

Would recommend changing:

$submenu['edit.php'][5][0] = 'News';
$submenu['edit.php'][10][0] = 'Add News';
$submenu['edit.php'][16][0] = 'News Tags';

...to...

  if (array_key_exists('edit.php', $submenu)) {
    $submenu['edit.php'][5][0]  = 'News';

    if (count($submenu['edit.php']) >= 11) {
      $submenu['edit.php'][10][0] = 'Add News';
    }

    if (count($submenu['edit.php']) >= 17) {
     $submenu['edit.php'][16][0] = 'News Tags';
    }
  }

...to fix the above error.

@jomko
Copy link

jomko commented Mar 8, 2016

@joeforshaw thank you!

@Aetles
Copy link

Aetles commented Aug 10, 2016

Just curious: why the echo ''; on line 17?

(I've seen this everywhere (like here, here, here, here and so on) so I'm curious if it is there by purpose or something everyone just copy and paste.)

@jonny-harte
Copy link

Hey! I'm trying to upgrade to PHP7 but the PHP compatibility checker is throwing an error which I think is on line 21.

"ERROR | Using a call-time pass-by-reference is deprecated since PHP 5.3 and prohibited since PHP 5.4"

Can this be modified to be compatible with PHP7?

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