我将以下代码添加到 WordPress 中的 functions.php 文件中,以向每篇博文添加“上次更新时间...”日期消息:
function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a');
$custom_content .= '<p class="last-updated">Last updated on '.
$updated_date . ' at '. $updated_time .'</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );
这在博客文章内容的顶部添加了类似的内容:https : //d3vv6lp55qjaqc.cloudfront.net/items/1Q0G0D1c3x313E1H0d05/Image%202018-06-19%20at%207.40.11%20AM.png? -CloudApp-Visitor-Id=2866569
是否可以编辑 PHP 代码,而不是将其添加到内容的顶部,而是将其添加到内容的底部?如果是这样,您能否向我提供代码示例?
谢谢!
试试这个。
function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a');
$custom_content .= '<p class="last-updated">Last updated on '.
$updated_date . ' at '. $updated_time .'</p>';
}
$content .= $custom_content;
return $content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句