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

Matthew McGarity matthew at mcgarity.me
Wed Aug 29 03:14:10 UTC 2012


Thanks for the alternate ways of coding using the "enter_title_here"
filter, guys.  My question remains outstanding -- if there's a way to
better target by the filter name itself, vs. having to account for it
within the function.

MMc...

Matthew McGarity
http://mcgarity.me

On Tue, Aug 28, 2012 at 9:54 PM, William Satterwhite <
whsatterwhite at gmail.com> wrote:

> My suggestion looks a little dated. Thanks for your example Justin.
>
> On Tue, Aug 28, 2012 at 12:19 AM, Justin Tadlock
> <justin at justintadlock.com>wrote:
>
> > 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 <wp-hackers at lists.automattic.com>
> >> http://lists.automattic.com/**mailman/listinfo/wp-hackers<
> http://lists.automattic.com/mailman/listinfo/wp-hackers>
> >>
> >>
> > ______________________________**_________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.**com <wp-hackers at lists.automattic.com>
> > http://lists.automattic.com/**mailman/listinfo/wp-hackers<
> http://lists.automattic.com/mailman/listinfo/wp-hackers>
> >
>
>
>
> --
> Hunter Satterwhite
> http://linkedin.com/in/hsatterwhite
> (252) 762-5177
> _______________________________________________
> 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