wordpress 前台文章显示日期改进法:
在wp-includes\functions.php 最后处增加:
//标题为空时,增加在文章处显示日期(有标题时会自动显示日期)。
function my_last_updated_date( $content ) {
$custom_content = '';
$cat_id = get_cat_ID('Category Name');
$cat_title = get_the_title($cat_id);
if ($cat_title == '') {
$updated_date = get_the_time( 'Y-m-j h:s a' );
$custom_content .= '<p class="last-updated entry-meta">Last Updated ' . $updated_date .'</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'my_last_updated_date' );
后续演变,我把上面的代码放在根add-functions.php文件中,然后在wp-includes\functions.php文件最后一行加入
require_once dirname( __DIR__ ) . '/add-functions.php';
这样子的好处就是如果WP有更新时,更新覆盖了wp-includes\functions.php文件,只需加上面那一行即可解决,后续如果有其他自定义代码功能,只要是涉及需要修改wp-includes\functions.php的,就直接转写到根add-functions.php文件中去即可。