Reputation: 4076
I am trying to find any titles that contain tags and preg_replace
the matching tag so there is a span
around it (to bold the tag).
This is what I have so far... The following code is just adding the_tags() to the end of the title. I am not too good with Wordpress and I know it's probably because the the_tags()
function includes other code such as "Tagged: " and "&mindot;".
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permalink to <?php the_title(); ?>">
<?php
$title = the_title();
$tags = array(the_tags());
$tag = implode(' ',$tags);
$displaytitle = preg_replace($tag, '<span class="larger">$tag</span>', $title);
echo $displaytitle;
?>
</a>
</h2>
Any help would be greatly appreciated.Thank you in advance!
Upvotes: 0
Views: 197
Reputation: 61
do not implode.
foreach($tags as $tag) {
$displaytitle = preg_replace($tag, "<span class=\"larger\">$tag</span>", $title);
}
should do the trick. Use double quotes to evalute variable inside.
Upvotes: 1