Wordpress php function to open all outbound links in new tab -
who wants virtual warm chocolate chip cookie?
i'm looking wordpress php function open outbound links in new tab.
i have found couple of function solutions similar 1 below, work posts/pages , not items hard-coded theme (like social media buttons):
/* open outbound links in new tab */ function autoblank($text) { $return = str_replace('href=', 'target="_blank" href=', $text); $return = str_replace('target="_blank" href="http://csihealth.lenadev.com', 'href="http://csihealth.lenadev.com', $return); $return = str_replace('target="_blank" href="#', 'href="#', $return); $return = str_replace(' target = "_blank">', '>', $return); return $return; } add_filter('the_content', 'autoblank'); add_filter('comment_text', 'autoblank');
is there way alter works outbound links? not posts/pages?
you jquery:
$(function() { $( 'a[href^="//"],a[href^="http"]' ) .not( '[href*="' + window.location.hostname + '"]' ) .attr('target', '_blank'); });
this find link not relative link (so, outbound), removes point own site, , set target blank left.
Comments
Post a Comment