Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 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>
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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