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

William Satterwhite whsatterwhite at gmail.com
Tue Aug 28 03:57:35 UTC 2012


I've always used the following:

function cpt_gettext( $text ) {
        global $post_type;

        if ( is_admin() && 'Enter title here' == $text && 'your_cpt' ==
$post_type ) {
            $text = 'Enter CPT name here';
        }

        return $text;
}
add_action( 'gettext', 'cpt_gettext' );

On Mon, Aug 27, 2012 at 11:52 PM, Matthew McGarity <matthew at mcgarity.me>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
>



-- 
Hunter Satterwhite
http://linkedin.com/in/hsatterwhite
(252) 762-5177


More information about the wp-hackers mailing list