我试图使页面字幕(http://www.nashebistro.cz/)成为当前日期。
我尝试使用短代码(https://wordpress.org/plugins/shortcode-for-current-date/)和Php <?php echo date('Y'); ?>
,但短代码没有正确显示,Php代码没有显示任何内容。
我真的很感激任何解决方案,提示,建议。
做这个。您必须创建一个新的DateTime实例并将其格式化为可以为html读取的字符串。
<?php echo date_format(new DateTime('Y'),"Y"); ?>
你也可以试试<?php the_time('Y'); ?>
请尝试使用本机WordPress功能“date_i18n”。所以你可以用文字显示月份(用你的wordpress语言)
<?php echo date_i18n( 'Y-m-d' ); ?>
https://codex.wordpress.org/Function_Reference/date_i18n
或者将它与ShortCode一起使用,在你的functions.php中使用它
if (!function_exists('topdaweb_shortcode_currentdate')) :
function topdaweb_shortcode_currentdate($atts) {
return date_i18n( 'Y-m-d' );
}
add_shortcode('currentdate', 'topdaweb_shortcode_currentdate');
endif;