How do I make URL auto recognized and changed to href html form in wordpress.
If I post:
http://stackoverflow.com/
I want it to automaticly go to:
<a href="http://stackoverflow.com/" target="_blank">My Text</a>
How do I make URL auto recognized and changed to href html form in wordpress.
If I post:
http://stackoverflow.com/
I want it to automaticly go to:
<a href="http://stackoverflow.com/" target="_blank">My Text</a>
You could do this with jQuery but if it when wrong/slow loading on page might yield odd results so your best bet is to us something like this in PHP
<?php
$url_pattern = "@(https?://([-\w\.]+)+(/([\w/_\.]*(\?\S+)?(#\S+)?)?)?)@";
$text = "This is my text, it make include a link like http://google.com or http://www.bbc.co.uk";
$replace = '<a href="$1" target="_blank">$1</a>';
$text = preg_replace($url_pattern, $replace, $text);
echo $text;
?>
You could set this into a little function and apply it as a filter to content before/as you output it onto your page(s) etc.
There are plugins available to do this in WordPress if you don't want to do it programmatically. Here are a couple: