例如我有“战舰预告片”的标题 所以它会生成这样的关键字 “最好,玩家,世界” 我怎么能这样做?
我想像这样的html apear ...
First:The
Second:Battleship
Third:Trailer
<meta name="keywords" content="<FirstWord>,<second>,<third>"/>
更确切地说,我想用文字分割标题。
我使用Wordpress
答案 0 :(得分:5)
echo '<meta name="keywords" content="'.implode(',', explode(' ', $string)).'"/>';
这会将$string
中空格分隔的单词与逗号连接起来。显然将$string
替换为适当的变量。
答案 1 :(得分:1)
$string = get_the_title(); // Inside your header.php
echo '<meta name="keywords" content="'.implode(',', explode(' ', $string)).'"/>';
答案 2 :(得分:1)
获得帖子的slu might可能会更好。这将消毒并删除任何对搜索引擎没有任何价值的短语。然后用PHP爆炸和内爆...
如何:
// Get the global post variable (inside or outside the loop)
global $post;
// Seperate title slug by dashes into array
$the_slug_into_array = explode('-', $post->post_name);
// Convert array back into a string with comma separation
$the_keywords = implode(',', $the_slug_into_array );
// Echo out the string of terms from the title
echo $the_keywords;
请告诉我这是否对您有用......