matthewpaul
Member
Posted 2 years ago #
I'm using this code to have tags as meta keywords:
<meta name="keywords" content="<?php
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ', ';
}
}
?>" />
It's adding a comma as a separator between each keyword. How can I remove the comma that shows up after the last keyword?
refulez
Member
Posted 2 years ago #
<meta name="keywords" content="<?php
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
?>" />
try this
matthewpaul
Member
Posted 2 years ago #
I want to keep the comma so that it properly separates the keywords in the meta tag. Just want to remove the comma from showing up after the last keyword.
try
<meta name="keywords" content="<?php
if ($posttags) {
$tags='';
foreach($posttags as $tag) {
$tags .= $tag->name . ', ';
}
echo substr($tags,0,-2);
}
?>" />
matthewpaul
Member
Posted 2 years ago #
Michael,
I tried replacing my code with yours, but no tags are showing up in the output.
Hmm...don't see a problem, so put you whole template in wordpress.pastebin.com and report the link back here and maybe someone can spot the problem.
skywolfyx1
Member
Posted 2 years ago #
paste function.php file
function csv_tags() {
$posttags = get_the_tags();
foreach((array)$posttags as $tag) {
$csv_tags .= $tag->name . ',';
}
if (is_home()) { ?>keyword1,keyword2,<?php }
echo "$csv_tags";
}
paste header.php between <head> </head
<meta name="keywords" content="<?php echo csv_tags(); ?>" />