tags:

views:

17

answers:

2

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? If, for whatever ridiculous reason, someone has JS disabled is why I ask.

Thanks!

+1  A: 

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/"&gt;Google&lt;/a&gt; should become just Google.

Martin Bean
Nice. That's perfect!
Marc
You may thank me by accepting then ;-)
Martin Bean
A: 

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.

Gavin