Basically, I have two words in every posts of my content, they are "Preview" and "Download". I want to apply an css class to style these two words as buttons. I can do it post by post, but it takes a lot of time and I think there should be a way to do it with coding.
I am using wordpress and can it be done using PHP? or any help or suggestion for this?
Thanks in advance guys!
$html=str_replace("Preview","<span class=\"AnyClass\">Preview</span>",$html);
And same for your other marker
$html=str_replace("Download","<span class=\"AnyClass\">Download</span>",$html);
Add this to your function.php
function replace_content($content)
{
$content = str_replace("Preview","<span class=\"AnyClass\">Preview</span>",$content);
$content = str_replace("Download","<span class=\"AnyClass\">Download</span>",$content);
return $content;
}
add_filter('the_content','replace_content');
// string
$str = 'Hello Preview and Download where are you?';
// Regex
echo preg_replace('/(Preview|Download)/im', '<span class="myclass">$1</span>', $str);
Output
Hello <span class="myclass">Preview</span>
and <span class="myclass">Download</span>
where are you?