I'm trying to strip all the a href tags from the_content();
when displayed on the front end. If I use get_the_content();
and preg_replace
it works fine, however, get_the_content doesn't show formatting such as
etc. When used with the_content();
, it doesn't strip the links out.
This strips out the links, but doesn't show the formatting such as <p>
:
$the_content = get_the_content();
$bad_tags = array('/<a title=\"(.*?)\" href=\"(.*?)\">/', '/<\/a>/');
$strip_tags = preg_replace($bad_tags, "", $the_content);
echo $strip_tags;
This DOESN'T strip out the links but does show the formatting:
$the_content = the_content();
$bad_tags = array('/<a title=\"(.*?)\" href=\"(.*?)\">/', '/<\/a>/');
$strip_tags = preg_replace($bad_tags, "", $the_content);
echo $strip_tags;
Thanks in advance for any help.