优化网站 SEO
, 自动将文章标签转化为关键字, 为文章添加 keywords
和 description
打开主题的 functions.php
添加以下代码:
functions.php1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <?php
function tag_to_keywords() { if ( is_single() ) { $posttags = get_the_tags(); if ( $posttags ) { foreach ( $posttags as $tag ) { $keywords [] = strtolower( $tag->name ); }; array_push( $keywords, "gelomen", "code cola", "code", "cola" ); ?> <!-- html --> <!-- 网站关键字, 用英文逗号隔开 --> <meta name="keywords" content="<?php echo implode( ",", array_unique( $keywords ) ); ?>"/> <!-- 网站的描述 --> <meta name="description" content="Gelomen 的个人博客网站。"/> <?php } } else { ?> <!-- html --> <!-- 网站关键字, 用英文逗号隔开 --> <meta name="keywords" content="gelomen,code cola"/> <!-- 网站的描述 --> <meta name="description" content="Gelomen 的个人博客网站。"/> <?php } } add_action('wp_head', 'tag_to_keywords');
|