Default Links to Open in New Window - i.e. Target = _blank

  1. Eva Marie

    Hello I am facing a problem in WordPress that if I add any link in my WordPress website page, after that when I click on that link it is opening in new tab that is irritating. I want to fix this problem. Anybody can help me to solve this issue. Here is my WordPress website http://www.essaybingo.com/.


    Eva Marie

    Posted: 6 years ago #
  2. Ian Dunn


    Hi Eva, this forum is for ideas to improve WordPress itself. The best place to post your issue is in the support forums at http://wordpress.org/support/

    Posted: 6 years ago #
  3. Eva Marie

    Ian Dunn, thanks you so much. Hope so this will be helpful for me :(.

    Posted: 6 years ago #
  4. bgal2012

    I know this is old, but if I found it today while I've I've been trying to do this then others probably do too... I finally found something worked.

    Add this to the bottom of your theme's function file (back up your site before messing with code):

    'function autoblank($text) {
    $myurl = 'http://puryourdomainhere.com';
    $external = str_replace('href=', 'target="_blank" href=', $text);
    $external = str_replace('target="_blank" href="'.$myurl, 'href="'.$myurl, $external);
    $external = str_replace('target="_blank" href="#', 'href="#', $external);
    $external = str_replace(' target = "_blank">', '>', $external);
    return $external;
    add_filter('the_content', 'autoblank');'

    I still have one link not cooperating, but it's from a plugin. Still working on that. All other external links on site are now opening in new tab :)

    Hope it helps.

    Posted: 5 years ago #
  5. stevemanser

    For creating links in menus that open in a new window; just click on Screen Options top left, all will become clear....

    Posted: 5 years ago #
  6. poweromania

    You can make all link open in new tab automatically by simply adding this code in the head section of your theme <base target="_blank">

    Posted: 1 year ago #

RSS feed for this topic


You must log in to post.

  • Rating

    12 Votes
  • Status

    This is plugin territory