Skip to:

Good grief this is ridiculous! (URLs)

  • I’ve read other posts on this, but I can’t get URLs to work with “target=_blank” when I add a link in a post. I use the BBcode-Lite plugin, and use blah, and have tried every variation of target=, with quotes, double quotes, slash quotes/double quotes – you name it. It all looks ok, but clicking the link always gives an error page of one form or another. Dammit, at this rate I’ll be on before long..!

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

  • chrishajer


    So you want links that are in replied to open in a _blank window? Just certain ones, or every one automatically? This would make any link posted in a reply open in a new windows (i.e. adds target="blank" to any link)”

    I’ve had a read through some of that (brain’s worn out!) but I don’t want to force all links to open new windows, just some to external sites. Users can go external, have a read, then close that window to return to my forum. So something like;

    Click here

    As none of the members know bbcode it’ll only be me doing it. Well, if I could get it working. Hmm… Sam’s code on one of those threads does it pre-post, so I guess that would work, unless I linked to another post, which I don’t want in a new window.

    Ok, so… I added the following code from another post to my bb-tweaks.php;

    // add nofollow to externa links only
    function target_nofollow_external_only( $text ) {
    $domain=""; // domain to exclude from target and nofollow
    // Strip ALL nofollow
    $text = preg_replace('|<a>|iU','</a><a>', $text);
    // Add back in when needed
    $text = preg_replace('|</a><a>]+http://))(?!([^>]+'.$domain.'))(.+)>|iU', '</a><a rel="nofollow">', $text);
    return $text;
    add_filter('post_text', 'target_nofollow_external_only',999);

    It stops my links from working somehow. They highlight, but don’t do anything when clicked. (Try



    They don’t do anything because they don’t go anywhere. Take a look at the source (from the page you linked):

    Get it at <a ></a>

    Looks like your regex is stripping out the link altogether.



    If it’s just you doing it and never a member, how about the “admin can post anything plugin”?

    Thanks, just installed that plugin, but it’s stripping out the URL. I posted;

    Click here to get it.

    and the other bb-tweak code I mentioned turned it into;

    <ablah rel=”nofollow” target=”_blank”>Click here</ablah> to get it.



    How about posting it as HTML not bbCode, if it’s just you?

    Yay – got it! I removed the ‘fix nofollow & _blank’ code, and discovered how to add the _blank in by experimenting. bbPress wraps the URL in double quotes, so I used this;

    Click here to get it.

    Works fine. Just got to add the nofollow bit back in, though that affects forum spidering from what one of those other posts says. Well, at least I can open external links in a new window (or tab in Chrome). Thanks for the help!

    I just re-added _ck_’s code to bb-tweaks;

    add_filter(‘post_text’, ‘bb_rel_nofollow’);

    but it isn’t adding the rel=”nofollow”. No worries though, this is fine;

    Click here to get it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar