[wp-hackers] "enter_title_here" filter and Appearance > Menus
Justin Tadlock
justin at justintadlock.com
Tue Aug 28 04:19:49 UTC 2012
Pulled from the code I use on my site:
add_filter( 'enter_title_here', 'th_enter_title_here', 10, 2 );
function th_enter_title_here( $title, $post ) {
if ( in_array( $post->post_type, array( 'theme', 'plugin', 'book' )
) ) {
$post_type = get_post_type_object( $post->post_type );
$title = sprintf( 'Enter %s name here', strtolower(
$post_type->labels->singular_name ) );
}
return $title;
}
On 8/27/2012 10:52 PM, Matthew McGarity wrote:
> My plugin utilizes a CPT, and I am using the "enter_title_here" filter to
> default the Title field on the CPT's Edit screen.
>
> In my original filter function, I initially forgot to call
> get_current_screen() & check that the current edit screen was for my CPT --
> so as you might expect, the title default occurred on Posts and Pages, not
> just my CPT. My code:
>
> function mcg_change_default_title( $title ) {
>
> $screen = get_current_screen();
>
> if ( 'mcg-cpt' == $screen->post_type ) {
> $title = 'foo';
> }
>
> return $title;
> }
>
> add_filter( 'enter_title_here', 'mcg_change_default_title' );
>
>
> One additional side effect I discovered is that Menus (under Appearance)
> are also targeted unless I add the screen check. So if I added a new Menu
> Item, it would rename.
>
> Questions:
>
> 1. Was this filter's effect on Menus intended? The only Trac ticket I
> could find was the one that implemented this filter, and it only discussed
> CPTs.
> 2. "enter_title_here" is not documented in the Codex. So I'm not aware
> if there's a alternate filter to more narrowly target the title (something
> like "enter_title_here_mcg-cpt", "enter_title_here-post", etc.). Is my
> code above the correct approach?
>
> Thanks in advance,
>
> MMc...
>
> Matthew McGarity
> http://mcgarity.me
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list