将帖子标记用于元关键字内容

问题描述 投票:1回答:5

似乎这应该超级简单,但我找不到合适的API函数来使其正常工作...

我想使用帖子标签来填充关键字元内容...

<meta name="keywords" content="tags from post go here seperated by commas">

我已经尝试过了,但是它创建了每个帖子标签的链接列表...

<meta name="keywords" content="<?php echo the_tags('',' , '); ?>" />

wordpress
5个回答
3
投票

尝试类似的东西:

<?php
  $postTags = get_the_tags();
  $tagNames = array();
  foreach($postTags as $tag) {
    $tagNames[] = $tag->name;
  }
?>

<meta name="keywords" content="<?php echo implode(",", $tagNames); ?>" />

1
投票

您需要使用模板函数get_the_tags来获取数据,而不是让WordPress为您输出数据。然后,您可以遍历此数组并输出列表,但是您需要:

get_the_tags

0
投票

the_tags()自动显示每个帖子标签的链接。您可以使用<?php if ( $posttags = get_the_tags() ) { foreach($posttags as $tag) echo $tag->name . ' '; } ?> 返回标签对象的数组,然后可以循环遍历并获取标签的名称。


0
投票

您可以尝试使用此方法:

get_the_tags()

0
投票

Oneline warriant for amercader版本。

<meta name="keywords" content="<?php if(is_single()) {
        $metatags = get_the_tags($post->ID);
        foreach ($metatags as $tagpost) {
            $mymetatag = apply_filters('the_tags',$tagpost->name);
            $keyword = utf8_decode($mymetatag); // Your filters...
            echo $keyword.",";
        }
    }
    ?>your,key,words" />
© www.soinside.com 2019 - 2024. All rights reserved.