Support » Plugins and Hacks » Hacks » Open links as _blank by default

  • as i haven’t found no clear solution here in the forum, digged a little and found that modifying wp-includes/bookmark-template.php we can achieve that

    locate:

    if ( '' != $target )
    $target = ' target="' . $target . '"';

    and add just afterwards:
    else $target = ' target="_blank"';

    if you want some link to open in the same window, mark its target as “_top”

Viewing 10 replies - 1 through 10 (of 10 total)
  • Anders

    (@seananders1227)

    Do you really want to be modifying the core?

    Why not just set _blank or whatever in the CMS?

    yep, i want to modify the core… i’ve imported lots of links and want the default target to be _blank… and haven’t found any hook or plugin to change this

    usually i keep track of the mods i do in the core or in the plugins i use, so in case of upgrade it’s easy to re-mod

    Anders

    (@seananders1227)

    Another option would be to use JavaScript that forces all external links, or all links within the particular widget, to open in a new window.

    I just hate seeing people modify the core!

    well, i’m gonna take a step further irritating you
    🙂

    a second mod is necessary so the link editor reflects the first mod,
    i mean, with the first one the links will open _blank,
    but the link property is showing _none

    so, in wp-includes/bookmark.php this is the mod to be done

    line 336, instead of:

    case 'link_target' : // "enum"
    	$targets = array('_top', '_blank');
    	if ( ! in_array($value, $targets) )
    		$value = '';
    	break;
    }

    it has to be:

    case 'link_target' : // "enum"
    	$targets = array('_top', '');
    	if ( ! in_array($value, $targets) )
    		$value = '_blank';
    	break;
    }

    Another option would be to use JavaScript that forces all external links, or all links within the particular widget, to open in a new window.

    I just hate seeing people modify the core!

    +1000, I read once that everytime someone modifies core a kitten dies…

    If you’re going to modify core, at least don’t promote it here!

    Future proof jQuery solution for anyone else looking for the same

    <script type="text/javascript">
    var $j = jQuery.noConflict();
    $j(document).ready(function() {
    	$j(".blogroll a").attr("target","_blank");
    });
    </script>

    i can see dead kittens…

    but, seriously, it’s not promotion, is investigation, and i don’t know of any other forum more appropriate to discuss WP than this one

    in any case, thanks a lot for bringing such an elegant and proper way to achieve the same result

    I hear you, and certainly don’t think you have anything against kittens : )

    Just thinking of the person who implements this core modification and then chases their tail for days after they upgrade and it breaks.

    Or, even worse, makes a very slight mistake and brings their entire install crashing down.

    Don’t edit core!

    madjax,
    nope, even though i’m more for dogs, i like kittens :o]

    and cool,
    now we have in the same thread the hardcore and the softcore solutions to the _blank issue

    cheers

    @esmi

    Edit the core: if you know what you’re doing!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Open links as _blank by default’ is closed to new replies.