Wordpress 3 - Remove Links from Posts via functions.php
Is there a way that I can remove links in posts via my functions.php file. Basically I don't want anyone to be able to go outside of the blog posts that are viewed. I have hundreds of posts so I obviously can't go through all of them and remove them manually. Or could I use javascript?
Thanks so much.
Updated: The jQuery below is great. Does anyone know if there is a way I can do it thru php in my functions.php file开发者_C百科? If, for whatever ridiculous reason, someone has JS disabled is why I ask.
Thanks!
You could use JavaScript, but you're not going to be able to stop people leaving if they want to.
Something like this may work, although I haven't tested and it was written off-hand:
<script>
$('#content a').each(function() {
$(this).replaceWith($(this).text());
});
</script>
With the jQuery library, this should replace all <a>
tags with what was in between them.
So <a href="http://www.google.co.uk/">Google</a>
should become just Google
.
You can strip out the links on the fly using a regular expression -
$post_content = get_the_content();
$post_content = preg_replace( "|<a *href=\"(.*)\">(.*)</a>|", "\\2", $post_content );
echo $post_content
This would need to go in your theme wherever you print the_content. Untested.
精彩评论