I am using str_replace to replace anything inside a link text (anchor text).
I want to replace the word ‘SMS’ from the anchor text inside a wordpress category name,
<?php echo str_replace("SMS","",(the_category(', '))) ; ?>
but it doesn’t work. It does work for a replacement of normal string,
$txt = "Sufyan"
<?php echo str_replace("S","a",$txt) ; ?>
The above code works but it doesn’t work when I want to replace something from anchor text.
the_category()is a template tag with echos its results without returning them. Basic rule of thumb: if it starts with ‘the_‘ it echos without returning.Change that line to
and
str_replace()should work as expected.