I learned a solution from https://stackoverflow.com/questions/36671203/wordpress-publish-date-shortcode

Although it can show the publish in the title, in the source code, it still shows the shortcode [post_published]. That means the search engine will not understand.

For example, assume the title name is "ABC", the result in the front end will show "ABC 2019/05/14", but in the source code it will show "ABC [post_published]", so in the Google search result, the title shows "ABC" only.

How can I do that the title will display the correct title name and publish date? Let it became "ABC 2019/05/14" not "ABC [post_published]"?


  • how did you used the shortcode?
    – Vishwa
    May 14, 2019 at 4:01
  • I just enter the shortcode in the title field. If the title is "ABC" then I enter "ABC [post_published]" May 14, 2019 at 8:17
  • please see my answer
    – Vishwa
    May 14, 2019 at 8:51
  • Hi @Vishwa, it still has the same issue. May 14, 2019 at 9:17

2 Answers 2


if the output you see is ABC [post_published], then it means your shortcode isn't working as it should. try including following code at the end of inside your theme's functions.php file.

function ppd_shortcode(){
  return get_the_date();
add_shortcode('ppdate', 'ppd_shortcode');

When you register a shortcode using the add_shortcode function, you pass in the shortcode tag ($tag) and the corresponding function ($func)/hook that will execute whenever the shortcut is used.

Important: When naming tags, use lowercase letters only, don't use hyphens, underscores are acceptable.

In this case, the shortcut tag is ppdate and the hook is ppd_shortcode. you can use the shortcode as [ppdate]

  • note, if this didn't work, try replacing return the_date(); with echo get_the_date();

Update: You said that your page title is working but meta title is still displaying wrong. Currently using Rank Math SEO, you can change the necessary page title as follows.

Go to Pages and select the page you want to edit. look for Page title SEO option, plugin has built in variables for you to use.

  • Hi @Vishwa, Thank you for the answer, but the solution is exactly the same as my previously provided. My issue is that when I add the shortcode in the title, it can work, but in the source code, it still displays [ppdate] (using your version). Like this: imgur.com/a/dojH8nC May 14, 2019 at 9:16
  • do you use any seo plugins?
    – Vishwa
    May 14, 2019 at 9:20
  • yes, I'm using Rank Math SEO. May 14, 2019 at 9:23
  • updated my answer. please note I don't have that plugin now, so I'm not sure exactly what variable you should use, but I gave best case for you to get an idea
    – Vishwa
    May 14, 2019 at 9:33
  • It's still not working. Instead of that, I'm made a solution which can work almost. add_filter( 'the_title', function( $title ) { if (is_single() && in_category(array(1738))) { return $title . ' ' . get_the_date(); } return $title; }); It has the same issue which the title can display but the <title> tag still shows the original title only. Can you check this solution? Thank you. May 14, 2019 at 9:44

You can use the the_title hook:

add_filter( 'the_title', function( $title ) {
  return $title . ' ' . get_the_date();
} );
  • Hi @Nicolai, Thank you very much, but what if I want to some specific posts (or a specific category's post) to show the publish date in the title, how can I set the condition? For now, the code will let all post have the date. May 14, 2019 at 8:40
  • Thank you, dude. I take your advice and do something Improvement, then made it work. Thx! May 14, 2019 at 10:11
  • @slivensliven Take a look at conditional tags for conditions. May 14, 2019 at 12:06

Your Answer

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

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