Changing the Default Enter title here Text

  • iftekhar
  • Jul 27, 2014
  • 0 comment
  • Print

Whenever you want to write a new blog post from WordPress, did you ever see the text “Enter title here” in gray color on the post title input field? I am joking, I know you have seen it many times.

Today in this post I will show you, how you can change the default “Enter title here” text to any text you want. I will also show how to change it for CPT (Custom Post Type). It could be really interesting to see the default title text as “Enter book title here” for a custom post type like “Books”, isn’t it? So, lets get started.

Default text for Posts

First thing first. I will focus on Posts section. This is the place where we mostly write our blog posts. To change the default text, take a look at the following snippet.

function custom_post_title_text($title) {
   $title = 'Enter your blog post title here'; 
   return $title; }

Snippet above will change the default text to “Enter your blog post title”. At this point, all you need to do is to change the value for $title variable and you are good to go. Don’t forget to copy and paste this snippet on your theme’s functions.php file and update it accordingly.

Note: This snippet is not recommended if you already have one or more custom post type registered. The reason behind that is, the snippet above would automatically change the default “Enter title here” text for your Custom Post Type(CPT) to “Enter your blog post title” as well. This is problematic. However, in that case you can easily follow the method I am about to mention below.

Default text for Custom Post Type

Let’s say you have a CPT called “Books” registered to write Book reviews and you also have “Posts” for writing regular blog posts. In such case we can easily change the default “Enter title here” text using the following snippet code.

function custom_post_title_text($title) {
   $screen = get_current_screen();
   if ('books' == $screen->post_type) {
      $title = 'Enter your book review title here';
   } else { 
      $title = 'Enter your blog post title here'; }
   return $title; } 

What is happening here is pretty easy to understand, let me break it down for you. At the very beginning, we are creating a function. On third line we declared $screen variable which returns an object with current screen’s information using get_current_screen function.

On fourth line, we are checking if the current screen’s information matches with the custom post type name “books”. If it does match, the title text should be “Enter your book review title here” for rest of the cases it should be “Enter your blog post title here”. Definitely you can change the CPT name (books) with your custom post type name and the value of $title variable with your desired text.

Just in case, if you don’t want to change the default text for Posts, you can simply remove the following line from your snippet.

else { $title = 'Enter your blog post title here'; }

That should let you change the default title text for CPT only.



Leave a Reply

Note: Convet HTML, PHP, JavaScripts from Postable, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.