关键词和描述标签作为SEO的基础配置,在wordpress中没有默认添加,这里记录一下在Wordpress中自动添加关键词和描述标签的方法。
实现思路是使用标签来作为关键词,使用文章摘要作为页面描述,找到使用主题的functions.php文件,添加以下代码即可实现。
/**
* 添加SEO相关的Keywords和Description标签
*/
function add_seo_meta_tags() {
if (is_home()) {
$tags = get_tags([
'number' => 15,
'orderby' => 'count',
'order' => 'DESC'
]);
$tags = array_map(function ($item) {
return $item->name;
}, $tags);
if (count($tags) > 0) {
?>
name;
}, get_the_tags() ?: []);
if (count($tags) > 0) {
?>
请注意,需要保证主题的header.php调用过wp_head()函数,类似下面:
class="no-js">
OK,这样我们就给所有页面都添加上关键词和描述标签了~
相关链接: