如何在WordPress中通过简码显示年份

非常简单的一个小技巧-通过shortcode(简码)显示年份。

将以下代码插入到主题文件functions.php中:

function year_shortcode() {
  $year = date('Y');
  return $year;
}
add_shortcode('year', 'year_shortcode');

用法:

在需要显示当前年份的页面或日志中插入【year】(使用时需将【】换成[])。

有关日期与时间格式的详细说明,大家可以参考WordPress官方相关文档,使用方法也可以举一反三,既然能够以这种方式显示年份,那么应该也可以显示月份、周、日或时间。

你可能还喜欢:

分享这篇日志:

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>