Skip to:
Content
Pages
Categories
Search
Top
Bottom

target _blank

  • After some searching @ this forum, I’m really confused on how to make replies links to open on a new window by default. I’ve found some tweaking plugins by CK, but I think that was a really early version and didn’t worked out.

    I’m using 9.0.4. Anyway to target=”_blank” links and bbCode-lite?

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

  • _ck_
    Participant

    @_ck_

    function bb_target_blank( $text ) {
    $text = preg_replace('|<a (.+?)>|i', '<a $1 target="_blank">', $text);
    return $text;
    }
    add_filter('post_text', 'bb_target_blank',255);

    Great, thanks CK!

    I tried this, I’m using 1.0.1

    And I got:

    Warning: Cannot modify header information – headers already sent by (output started at /home/onlin196/public_html/forums/my-plugins/tabbladen.php:14) in /home/onlin196/public_html/forums/bb-includes/functions.bb-pluggable.php on line 232

    Below you have the whole code i used

    <?php

    /*

    Plugin Name: Nieuwe tabblad openen

    Plugin URI: http://bbpress.org

    Description: opent links in een nieuwe venster

    */

    function bb_target_blank( $text ) {

    $text = preg_replace(‘||i’, ‘‘, $text);

    return $text;

    }

    add_filter(‘post_text’, ‘bb_target_blank’,255);

    ?>

    Check for a trailing space or anything after the ?> or before the <?php. That error implies that some text is being passed and in my test install, that was a space after the ?>.

    OKay, I fixed that and don’t get the error anymore. Thanks.

    However I thought the point of this plugin was to open all external links in a new tab, but that’s not really happening :(

    What was the exact point of this plugin? The first post is a bit confusing, I guess.

    Quick check, your code does actually include the <a (.+?)> part right? That got dropped from your post, but I’m presuming that’s because you didn’t use the code tag. The plugin should add the target=”_blank” HTML attribute, which tells the browser to open the link in a new window. You can change that in the browser to open in a new tab instead, but if it’s not doing either of those, there’s something wrong.

    That was indeed the problem :(

    The plugin is working.

    If i detect errors, I’ll report it here.

    Thanks very much for your help.

    Great idea!

    I’ve applied this way and works fine … 

    <?php

    /*

    Plugin Name: Target Blank

    Plugin URI: https://bbpress.org/forums/topic/target-_blank

    Description: Abre los enlaces del foro en nueva ventana. Nada que configurar, lo activas y funciona. Creado desde una idea de _ck_.

    */

    function bb_target_blank( $text ) {

    $text = preg_replace('||i', '', $text);

    return $text;

    }

    add_filter('post_text', 'bb_target_blank',255);

    ?>

    Thanks _ck_ ;)

    I noticed that it also opens links to internal pages in a new tab, I was hoping it would only do that with external links…

    This is pretty simplistic regex, you’d need something that checked the URL host again the local address for that. Probably do-able using regex, but I can’t write it to save my life…

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