我想从中删除元关键字标签中的尾随逗号:
<meta name="keywords" content="enhancing,nutritional,supplements," />
对此:
<meta name="keywords" content="enhancing,nutritional,supplements" />
这是完整的代码。
/* 自动为 Genesis 框架中的 SEO 生成帖子/页面元关键字。如果 Genesis 没有返回关键字,则关键字是从帖子标签或
帖子/页面标题自动生成的。*/
add_action( 'genesis_meta', 'my_auto_keywords' , 11 );
function my_auto_keywords(){
if(
!is_singular() ||
genesis_get_custom_field( '_genesis_keywords' ) ||
genesis_get_custom_field( '_aioseop_keywords' ) ||
genesis_get_custom_field( 'thesis_keywords' ) ||
genesis_get_custom_field( 'keywords' )
) return;
$tags = get_the_tags(); #wp
if ($tags) {
foreach ($tags as $tag) {
$keywords .= $tag->name . ', ';
}
}
if ($keywords) {
$keywords = '<meta name="keywords" content="' . $keywords . '" />';
}
else {
$title = get_the_title();
$keywords = preg_split("/[\s,]+/", $title);
$keywords = array_map('strtolower', $keywords);
$keywords = array_diff($keywords, my_excluded_words()); //remove useless words
foreach ($keywords as $keyword)
$kw_list .= $keyword . ',';
$keywords = '<meta name="keywords" content="' . $kw_list . '" />';
}
echo $keywords . "\r\n";
}
function my_excluded_words(){
return array ("testword", "testword2", "testword3", "testword4");
}