How to change the admin menu “Pages” to something else

When one creates a custom post type you have the ability to define various elements related to that post type which essentially allow you to define things such as the menu title, “add new post” text and stuff like that.

What I am trying to figure out is what code I need to add to my functions.php file so I can set these things for an existing “default” post type which wordpress adds.

So, for example lets say I want to change the “Pages” post type to “Main Sections”.

Currently what I have done is used the following code:

add_filter( 'gettext', 'change_admin_menu_pages' );
add_filter( 'ngettext', 'change_admin_menu_pages' );
function change_admin_menu_pages( $translated ) {
    $translated = str_replace( 'Page', 'Core Page', $translated );
    $translated = str_replace( 'page', 'core page', $translated );
    return $translated;
}

Although this works and just replaces every instance of “pages” with “main sections”, what I have noticed is that it also effects other areas of the site such as plugins which use “pages=” within their url.

As such… is there a simple way to define post type settings for default wordpress post types like “pages” and “posts”? If so, could someone please quickly illustrate how that might work?

On a different note… I feel that using the filter

  • add_filter( ‘ngettext’,…)

is actually very useful but what I don’t understand is how to restrict the area where its allowed to filter things.

An answer to both or either question would be greatly appreciated

Thanks in advance!

2 Answers
2

Another easy one! 🙂

As you know I think very highly of WordPress in general, but the admin menu architecture is one of the nastiest hacks I think I’ve ever seen in open-source software. What’s only greater in magnitude is the core WordPress team’s unwillingness to acknowledge how bad it is and their lack of willingness to discuss improving it. But I digress…

Anyway, here’s what you want (I think):

Screenshot of a WordPress admin menu modified to
(source: mikeschinkel.com)

And here’s how to get it:

add_action('admin_menu','rename_pages_to_main_sections');
function rename_pages_to_main_sections() {
  global $menu;
  global $submenu;
  $menu[20][0] = 'Main Sections';
  $submenu['edit.php?post_type=page'][5][0] = 'Main Sections';
}

P.S. Also, you might find the code I posted here helpful too:

  • How to Resolve Some Challenges when Modifying the WordPress Admin Menu System?

Leave a Comment