• Hello every one, i recently made all links in my website clickable using this code
    add_filter(‘the_content’, ‘make_clickable’);

    i have a lot of unclickable links so this solved the problem but i would like them to sent to external tabs. Can some pliz help me with a code to enable that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • What’s the code in the make_clickable function? All you need ot do is edit that to add in the extra code to make the link open in a new window.

    Moderator bcworkz

    (@bcworkz)

    Whoa! catacaustic clearly does not realize that make_clickable() is a WP core function! We never edit core functions and catacaustic knows this 🙂

    Unfortunately, this function is lacking any kind of filter that we often see in core, so your only clean recourse is to copy the source code into a child theme or your own plugin, giving it a new name, editing as needed, then calling it by the new name. It’s in /wp-includes/formatting.php.

    The only thing to change here is the callback function (line 2236 in formatting.php) _make_url_clickable_cb. You’ll need to copy and rename the source for this function too (also in formatting.php, a few functions up from make_clickable()). In the callback all you need to do is edit the return string at the end of the function to this:
    return $matches[1] . "<a href=\"$url\" rel=\"nofollow\" target=\"_blank\" >$url</a>" . $suffix;

    You’re right bcworkz, I did not realise that it was a core function. I’ll jsut get my geek card ready to hand in now… 😉

    @febday, follow that advice above. It’s the best way to do what you’re after.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘making urls clickables’ is closed to new replies.