Auto convert WordPress post content URLs to Hyperlinks and open in a new window
Posted on | January 26, 2011 | 2 Comments
I needed to have all of my post content plain text URLs converted to Hyperlinks, but it needs to open in a new window when clicked. The make_clickable() function in wordpress doesn’t allow to specify any option for the target.
function make_clickable2($content) {
$content = preg_replace("/http:\/\/[a-zA-Z.&\-\/]+[a-zA-Z&\-\/]+/", "<a href=\"\${0}\" target=\"_blank\">\${0}</a>", $content);
return $content;
}
add_filter('the_content', 'make_clickable2');
Comments
2 Responses to “Auto convert WordPress post content URLs to Hyperlinks and open in a new window”
Leave a Reply


1128
21
3
0
0
1059
57
55
15
11
1
0
0
0
0
0
0
April 8th, 2011 @ 3:23 am
An easier way would be to just use the links_add_target function. So if you used the code you would get the same result without adding your own function.
April 8th, 2011 @ 3:25 am
oh sorry, your site removed my code since I put it in php tags, but it would just be “links_add_target(make_clickable($link))”