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);
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…