0

I have alot of old posts that are being pulled with the_content() context.

In the_content() there is links in the text, however none of them are hyperlinked it just shows like http://twitter.com/twitterrocks with it not linked. Is there a way to link all links in my the_content() and make them target="_blank" ?

Thanks in advance!

1

Running make_clickable on the_content will get you your links. So...

apply_filters('the_content','make_clickable');

... in your functions.php should link your content. It will be simple but you should get hyperlinks.

I don't see a way to add the target="_blank" part. make_clickable is in wp-includes/formatting.php. You could use it as a pattern for a function that would add the target="_blank".

Or you could force a jquery script to change all the links' targets to blank. Here's the code for that -

<script src="jquery-1.5.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$('a').attr("target", "_blank");
</script>
  • The jQuery option was suggested by kidakaka – s_ha_dum Nov 6 '12 at 4:19
  • 1
    except you don't want to include jQuery that way, you will break plugins that use it. Use WordPress's version via wp_enqueue_script and note that WordPress jQuery is in noConflict mode. – Milo Nov 6 '12 at 4:53
  • 1
    should be apply_filters instead of apply_filter, right? – Sebastian Hojas Nov 11 '13 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.