使用代码方式显示WordPress文章最后修改时间
使用代码的方法添加WordPress文章最后修改时间,把下面的代码添加到你文章主题函数里
//文章显示最后更新时间 function wpb_last_updated_date( $content ) { $u_time = get_the_time('U'); $u_modified_time = get_the_modified_time('U'); $custom_content = ''; 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' );
然后就是设置最后更新时间的显示效果,下面是奶爸目前用的样式,添加到你主题的css里面。
.last-updated { color: #db7c22; background: #fff4b9; border: 1px solid #eac946; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px; font-size: 14px; }