Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created March 27, 2011 17:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefuxia/889394 to your computer and use it in GitHub Desktop.
Save thefuxia/889394 to your computer and use it in GitHub Desktop.
Renames the first submenu item for a custom post type
<?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';
}
@thefuxia
Copy link
Author

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