target=”_blank” did not work out of the box for me
-
so I changed the two functions to look like so:
function parse_external_links($matches){ global $txfx_iel_use_target_blank; $addtext = ($txfx_iel_use_target_blank)? ' class="extlink" target="_blank"' : ' class="extlink"'; if ( wp_get_domain_name_from_uri($matches[3]) != wp_get_domain_name_from_uri($_SERVER["HTTP_HOST"]) ){ return '<a href="' . $matches[2] . '//' . $matches[3] . '"' . $matches[1] . $matches[4] . $addtext . '>' . $matches[5] . '</a>'; } else { return '<a href="' . $matches[2] . '//' . $matches[3] . '"' . $matches[1] . $matches[4] . '>' . $matches[5] . '</a>'; } }
and
function wp_external_links($text) { global $txfx_iel_use_target_blank; $pattern = '/<a (.*?)href="(.*?)\/\/(.*?)"(.*?)>(.*?)<\/a>/i'; $text = preg_replace_callback($pattern,'parse_external_links',$text); $pattern2 = '/<a (.*?) class="extlink"(.*?)>(.*?)<img (.*?)<\/a>/i'; $text = preg_replace($pattern2, '<a $1 $2>$3<img $4</a>', $text); return $text; }
also, it might be a good idea to add a variable so that stripping the extlink class from image tags is optional. you’d just need a boolean variable like is implemented for the _blank option and then replace
$pattern2 = '/<a (.*?) class="extlink"(.*?)>(.*?)<img (.*?)<\/a>/i'; $text = preg_replace($pattern2, '<a $1 $2>$3<img $4</a>', $text);
with
if($stripclass){ $pattern2 = '/<a>(.*?)<img (.*?)<\/a>/i'; $text = preg_replace($pattern2, '</a><a>$3<img $4</a>', $text); }
- The topic ‘target=”_blank” did not work out of the box for me’ is closed to new replies.