Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Open Links in new window

I can’t seem to get _ck_’s plugin to work, everytime I use it takes away the a href…

<?php
/*
Plugin Name: Target Nofollow External Only
Description: append target="_blank" and rel="nofollow" only on external links
Plugin URI:
Author: _ck_
Version: 0.0.1
*/

add_filter('post_text', 'target_nofollow_external_only',999); // unfortunately we have to do this on every page load and not in pre_post

function target_nofollow_external_only( $text ) {
$domain="easyloungin-forum.com"; // domain to exclude from target and nofollow
$text = preg_replace('|<a (.*)rel=['"]nofollow['"](.+)?>|iU','<a >', $text); // strip ALL nofollow
$text = preg_replace('|<a (?=([^>]+http://))(?!([^>]+'.$domain.'))(.+)>|iU', '<a rel="nofollow" target="_blank">', $text); // add back in when needed
return $text;
}
?>

Skip to toolbar