[wp-hackers] "enter_title_here" filter and Appearance > Menus

Matthew McGarity matthew at mcgarity.me
Tue Aug 28 03:52:47 UTC 2012


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


More information about the wp-hackers mailing list