最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to add publish date in the title

programmeradmin3浏览0评论

I learned a solution from

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]"?

Thanks.

I learned a solution from https://stackoverflow/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]"?

Thanks.

Share Improve this question asked May 14, 2019 at 0:36 sliven slivensliven sliven 33 bronze badges 4
  • how did you used the shortcode? – Vishwa Commented 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]" – sliven sliven Commented May 14, 2019 at 8:17
  • please see my answer – Vishwa Commented May 14, 2019 at 8:51
  • Hi @Vishwa, it still has the same issue. – sliven sliven Commented May 14, 2019 at 9:17
Add a comment  | 

2 Answers 2

Reset to default 0

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.

You can use the the_title hook:

add_filter( 'the_title', function( $title ) {
  return $title . ' ' . get_the_date();
} );

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论