23

I have a custom post type created for a directory that will end up being sorted alphabetically. I will be sorting the posts in alphabetical order by title, so I want to make sure that the Title is entered as last name/first name. Is there a way to change that default help text -- "Enter Title Here" -- in my custom post to something else?

1
  • 1
    For people looking at this question now (since WordPress 3.1) please see some of the newer answers below for a better (more "WordPress Way" solution).
    – Tom Auger
    Dec 6, 2016 at 17:02

5 Answers 5

23

There is no way to customize that string explicitly. But it is passed through translation function and so is easy to filter.

Try something like this (don't forget to change to your post type):

add_filter('gettext','custom_enter_title');

function custom_enter_title( $input ) {

    global $post_type;

    if( is_admin() && 'Enter title here' == $input && 'your_post_type' == $post_type )
        return 'Enter Last Name, Followed by First Name';

    return $input;
}
2
  • 5
    Use the filter enter_title_here
    – Pbearne
    Jan 18, 2016 at 20:27
  • 2
    Good, but see the new answers below.
    – Mark
    Oct 26, 2016 at 21:23
43

I know I'm a little late to the party here, but I'd like to add that the enter_title_here filter was added specifically for this purpose in WordPress v3.1.

add_filter( 'enter_title_here', 'custom_enter_title' );
function custom_enter_title( $input ) {
    if ( 'your_post_type' === get_post_type() ) {
        return __( 'Enter your name here', 'your_textdomain' );
    }

    return $input;
}

Change your_post_type and your_textdomain to match your own post type name and text domain.

1
  • 6
    Small clarification. Shouldn't be any need for the is_admin() check as this filter itself will only fire when in the admin area. If for some reason you had a front-end form, it's very conceivable that you would want this filter applied anyway. Feb 9, 2013 at 22:30
8

Sorry to dig this question up from grave, but there's a better solution provided since WordPress 3.1. The enter_title_here filter.

function change_default_title( $title ){
    $screen = get_current_screen();

    // For CPT 1
    if  ( 'custom_post_type_1' == $screen->post_type ) {
        $title = 'CPT1 New Title';

    // For CPT 2
    } elseif ( 'custom_post_type_2' == $screen->post_type ) {
        $title = 'CPT2 New Title';

    // For Yet Another CPT
    } elseif ( 'custom_post_type_3' == $screen->post_type ) {
        $title = 'CPT3 New Title';
    }
    // And, so on

    return $title;
}

add_filter( 'enter_title_here', 'change_default_title' );
2
  • 2
    New constructive answers are always welcome. May 23, 2014 at 7:37
  • This is the correct (modern) answer, however Martin-Al's answer remembers to use the gettext localization wrapper function, so should be carefully studied as well: wordpress.stackexchange.com/a/6819/3687
    – Tom Auger
    Dec 6, 2016 at 16:55
5

Take a look in wp-admin/edit-form-advanced.php at line 246 (line 329, as of WP3.5)

<label class="screen-reader-text" id="title-prompt-text" for="title">
<?php echo apply_filters( 'enter_title_here', __( 'Enter title here' ), $post ); ?>
</label>
1
2

The best way to get the title format you want is to remove the title completely and add two custom fields for the name parts with proper labels. When the post is saved, create the title per PHP.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.