i've just created a new post type. It's name is Academias so the first menu option is Academias as well. But I would like to change it to something like See All Academias (just an example), is that possible?
-
Where specifically do you want to see the phrase "See All Academias?"– MikeSchinkelMar 27, 2011 at 15:45
-
Mike, at the Main menu text, where you have the button that shows the drop down options. But I think toscho answer solves the problem– Vitor ArgosMar 27, 2011 at 16:35
-
Yes, @toscho answered it, great! (I was just doing my part to coach on how to write questions that require you to answer fewer follow up questions!)– MikeSchinkelMar 28, 2011 at 3:13
1 Answer
The function register_post_type() takes an argument 'labels'
. This is an array, one of the possible keys is named … tada! … 'menu_name'
.
Sample code
register_post_type(
'academias'
, array (
'can_export' => TRUE
, 'exclude_from_search' => FALSE
, 'has_archive' => TRUE
, 'hierarchical' => TRUE
, 'label' => 'Academias'
, 'labels' => array ( 'menu_name' => 'See All Academias' )
, 'menu_position' => 5
, 'public' => TRUE
, 'publicly_queryable' => TRUE
, 'query_var' => 'academias'
, 'rewrite' => array ( 'slug' => 'academias' )
, 'show_ui' => TRUE
, 'show_in_menu' => TRUE
, 'show_in_nav_menus' => TRUE
, 'supports' => array ( 'editor', 'title' )
)
);
Update
Now, that I’ve understood your question better, there seems to be only one way to accomplish what you want: hook into attribute_escape
.
Test Plugin
<?php
/*
Plugin Name: *WPSE13210
*/
! defined( 'ABSPATH' ) and exit;
add_action( 'init', 'register_academia' );
/**
* Registers te post type academias
*
* @return void
*/
function register_academia()
{
register_post_type(
'academias'
, array (
'can_export' => TRUE
, 'exclude_from_search' => FALSE
, 'has_archive' => TRUE
, 'hierarchical' => TRUE
, 'label' => 'Academias'
, 'labels' => array (
'menu_name' => 'See All Academias'
, 'name' => 'Academias'
)
, 'menu_position' => 5
, 'public' => TRUE
, 'publicly_queryable' => TRUE
, 'query_var' => 'academias'
, 'rewrite' => array ( 'slug' => 'academias' )
, 'show_ui' => TRUE
, 'show_in_menu' => TRUE
, 'show_in_nav_menus' => TRUE
, 'supports' => array ( 'editor', 'title' )
)
);
}
add_filter( 'attribute_escape', 'rename_second_menu_name', 10, 2 );
/**
* Renames the first occurence of 'See All Academias' to 'Academias'
* and deactivates itself then.
* @param $safe_text
* @param $text
*/
function rename_second_menu_name( $safe_text, $text )
{
if ( 'See All Academias' !== $text )
{
return $safe_text;
}
// We are on the main menu item now. The filter is not needed anymore.
remove_filter( 'attribute_escape', 'rename_second_menu_name' );
return 'Academias';
}
Not very elegant, but at least a solution …
Update 12.05.2010
In ticket 17378 a new parameter all_items
was proposed. That should work much better, once it’s part of the core …
-
Hi toscho, thanks for your asnwer, but that`s not exactly what I want. When I set an value for menu_name it changes the menu page name and also the sub menu page name. I have that: Academias -> Academias, Add New and I want Academias -> See all Academias, Add new Mar 27, 2011 at 15:36
-
-
Hey toscho, ok I applied it to my functions.php and I have a little problem. When the function actually works my admin dashboard gets a broken style. Also i read a little about this filter and it
s deprecated, wouldn
t it be a problem? (I`m new to wordpress programming hehe) Mar 27, 2011 at 17:09 -
@Vitor Argos the function with the same name is deprecated, not the filter. Did you copy the last
}
? For no obvious reason the highlighter takes it out of the code block. In my tests the plugin worked just fine. Use the code from gist.github.com/889394– fuxia ♦Mar 27, 2011 at 17:32 -
Oh, thanks toscho. I tried to edit the code but i did a stupid mistake thats why it was not working. Everything is fine now, thanks a lot for you help! Mar 27, 2011 at 18:05