本次分享的代码只会在文章和页面中添加时间因子,如果有其他需要,可以在此基础上进行修改。
1、方法一
编辑主题的header.php文件,在</head>标签前面添加以下代码:
<?php if ( is_single() || is_page() ) { ?>
<meta property=”bytedance:published_time” content=”<?php echo get_the_time(‘Y-m-d\TH:i:s+08:00’); ?>” />
<meta property=”bytedance:updated_time” content=”<?php echo get_the_modified_time(‘Y-m-d\TH:i:s+08:00’); ?>” />
<?php } ?>
保存即可生效。
2、方法二
编辑主题的functions.php文件,在文件末尾添加以下代码:
add_action( ‘wp_head’, ‘toutiao_search_time_factor’ );
function toutiao_search_time_factor() {
if ( is_single() || is_page() ) {
echo ‘<meta property=”bytedance:published_time” content=”‘,get_the_time(‘Y-m-d\TH:i:s+08:00’),‘” />’,“\r\n”;
echo ‘<meta property=”bytedance:updated_time” content=”” content=”‘,get_the_modified_time(‘Y-m-d\TH:i:s+08:00’),‘” />’,“\r\n”;
}
}
保存即可生效。