Custom Post Types are an increasingly popular tool for WordPress developers to use when constructing their plugins. There are many, many little tricks that help to make the finished product more polished, and one of those is changing the “Enter title here” text that is displayed in the Post Title field on the edit screen. This quick tip will show you have to change that text to anything you want.


[box style=”notice”]This is a quick tip. Check out more Quick Tips[/box]

All that is required is a single, simple function. Place the code below in your plugin file (or functions.php works fine too for theme developers):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// changes the "Enter title here" to "Enter question here" for FAQs
add_filter('gettext', 'faq_custom_rewrites', 10, 4);
function faq_custom_rewrites($translation, $text, $domain) {
	global $post;
        if ( ! isset( $post->post_type ) ) {
            return $translation;
        }
	$translations = &get_translations_for_domain($domain);
	$translation_array = array();
 
	switch ($post->post_type) {
		case 'faqs': // enter your post type name here
			$translation_array = array(
				'Enter title here' => 'Enter question here'
			);
			break;
	}
 
	if (array_key_exists($text, $translation_array)) {
		return $translations->translate($translation_array[$text]);
	}
	return $translation;
}

Just change the post type name after the case to the name of your custom post type. Note that you can change the text for multiple post types in a single function by simply entering more than one case argument.

Enjoy!

  1. Travis Smith

    Courtesy of @_mfields, you need to add:
    if ( ! isset( $post->post_type ) ) {
    return $translation;
    }
    to line 5.

    • pippin

      @Travis Thanks for letting me know, and thanks to Michael!

Comments are closed.