1

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!

7

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:

0

Mike, you should have put a little 'sarkasm' tag on the 'Another easy one!' line...for a moment there i didn't quite see how hacking the core menu arrays is an easy one...until i read your 'Challenge'.

I've got a similar challenge using 3.0.5...which is to try and add a custom page underneath a custom post types section. When doing so, it always loads as edit.php?post_type=xyz .

Fun is, edit.php includes admin-header.php, which in turn then includes admin.php, which then causes the page you specified via add_submenu_page() to be loaded. But first of all, this seems more like a lucky conincidence, secondly, it does that only after edit.php did all it's initialization stuff. BAD.

Furthermore, it leads to trouble down the road when you try to reuse your URL or parts of it (like query args and the likes) on your page.

All in all, i totally agree...this stuff is way too easy to do to justify an overhaul of the admin menu generation. ;-)

Thanks anyways, for your hint, i'm gonna try what i can achieve by hacking the arrays directly, now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.