简体   繁体   English

在WordPress中将日期转换为ISO-8601

[英]Converting date to ISO-8601 in WordPress

I know that there are many examples of how to convert a date to ISO-8601 format with php, but how would I convert a date to 8601 for search engines but still display the standard date format (May 10, 2015) for users? 我知道有很多示例如何使用php将日期转换为ISO-8601格式,但是对于搜索引擎我如何将日期转换为8601,但仍为用户显示标准日期格式(2015年5月10日)? I ask for the purpose of structured data markups, which require the dates to be in ISO-8601 format. 我要求提供结构化数据标记,目的是要求日期采用ISO-8601格式。 I am editing a WordPress template and this is the current php script that posts the date to the page: 我正在编辑WordPress模板,这是将日期发布到页面的当前php脚本:

<?php echo date('F d, Y',strtotime($post_date[0])); ?>

So in other words, I'd still like to display the date in the standard format but also generate the date in 8601 format that only crawlers can see, within a markup such as: 因此,换句话说,我仍然想以标准格式显示日期,但还要在标记之类的格式中生成仅爬网程序可以看到的8601格式的日期:

<meta itemprop="datePublished" content="2015-05-15">

Thanks in advance. 提前致谢。

You can use a built in WordPress function: 您可以使用内置的WordPress功能:

the_time( 'c' )

And display like this: 并显示如下:

<meta itemprop="datePublished" content="<?php the_time( 'c' ); ?>">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM