Info
- 11 posts
- 5 voices
- Started 2 years ago by filiped
- Latest reply from Adam Harley
- This topic is resolved
target _blank
-
- Posted 2 years ago #
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?
-
- Posted 2 years ago #
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); -
- Posted 2 years ago #
Great, thanks CK!
-
- Posted 2 years ago #
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 232Below 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);?>
-
- Posted 2 years ago #
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?>. -
- Posted 2 years ago #
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.
-
- Posted 2 years ago #
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. -
- Posted 2 years ago #
That was indeed the problem :(
The plugin is working.
If i detect errors, I'll report it here.
Thanks very much for your help.
-
- Posted 2 years ago #
Great idea!
I've applied this way and works fine …
<?php
/*
Plugin Name: Target Blank
Plugin URI: http://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_ ;)
-
- Posted 2 years ago #
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...
-
- Posted 2 years ago #
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...
-
You must log in to post.