WordPress.org

Ready to get started?Download WordPress

Forums

Open links as _blank by default (11 posts)

  1. brasofilo
    Member
    Posted 2 years ago #

    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"

  2. Anders
    Member
    Posted 2 years ago #

    Do you really want to be modifying the core?

    Why not just set _blank or whatever in the CMS?

  3. brasofilo
    Member
    Posted 2 years ago #

    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

  4. Anders
    Member
    Posted 2 years ago #

    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!

  5. brasofilo
    Member
    Posted 2 years ago #

    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;
    }
  6. Jackson
    Member
    Posted 2 years ago #

    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>
  7. brasofilo
    Member
    Posted 2 years ago #

    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

  8. Jackson
    Member
    Posted 2 years ago #

    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.

  9. esmi
    Forum Moderator
    Posted 2 years ago #

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

    Don't edit core!

  10. brasofilo
    Member
    Posted 2 years ago #

    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

  11. brasofilo
    Member
    Posted 2 years ago #

    @esmi

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

Topic Closed

This topic has been closed to new replies.

About this Topic