两种方法,效果都是一样的,推荐方法二。
- code snippets中,插入如下代码即可,类型选择html,然后在标题中插入快捷代码:
此方法生成的年份,会默认带p标签,需要手动添加一条css使他display:inline,否则会另起一行
- 使用code snippets插件,添加如下代码,在前端执行即可:
在标题中,插入快捷代码:,系统就会自动替换成当前的年份
php
12345678910
//* Activate shortcode function in Post Title
add_filter( 'the_title', 'do_shortcode' );
//* Shortcode to display the current year in WordPress
//* shortcode:
add_shortcode( 'year' , 'current_year' );
function current_year() {
$year = date("Y");
return "$year";
}