1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Wordpress Open All Internal Links In New Tab

Discussion in 'Blogging' started by tompots, Jun 26, 2013.

  1. tompots

    tompots Elite Member Premium Member

    Joined:
    Dec 11, 2011
    Messages:
    4,352
    Likes Received:
    3,955
    Gender:
    Male
    Occupation:
    Full Time Bot Developer
    Location:
    Professional Botters
    Home Page:
    Yes I have (G)ed it but I only find old out dated information that no longer works, if you know how to Open All Internal Links In New Tab with Wordpress or know how to make a quick plug in with Pluginception please let me know.
     
  2. tompots

    tompots Elite Member Premium Member

    Joined:
    Dec 11, 2011
    Messages:
    4,352
    Likes Received:
    3,955
    Gender:
    Male
    Occupation:
    Full Time Bot Developer
    Location:
    Professional Botters
    Home Page:
  3. SmartMan

    SmartMan BANNED BANNED

    Joined:
    Jul 25, 2012
    Messages:
    673
    Likes Received:
    1,244
    Goto Appearance -> Editor -> header.php

    Insert following code just above the closing </head> tag and click on the Update File.

    Code:
    <script language=javascript>
    
    
    function externalLinks()
    {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++)
    {
    var anchor = anchors[i];
    if(anchor.getAttribute("href"))
    anchor.target = "_blank";
    }
    }
    window.onload = externalLinks;
    
    
    </script>
    
    Note : This is going to seriously affect the usability of your site and annoy both you and your users as they're going to end up with dozens of windows before they ditch your site. It opens every link you click in a new window even if it's inside the WP Admin Area. Continue at your own risk. HTH
     
    • Thanks Thanks x 1
  4. Repulsor

    Repulsor Power Member

    Joined:
    Jun 11, 2013
    Messages:
    707
    Likes Received:
    267
    Location:
    PHP Scripting ;)
    Quick Edit : Looks like it is answered now ^^
     
    • Thanks Thanks x 1
  5. tompots

    tompots Elite Member Premium Member

    Joined:
    Dec 11, 2011
    Messages:
    4,352
    Likes Received:
    3,955
    Gender:
    Male
    Occupation:
    Full Time Bot Developer
    Location:
    Professional Botters
    Home Page:
    Thank you so much! would it be possible to make the code only open to certain links in the new tab except all the links?
     
  6. SmartMan

    SmartMan BANNED BANNED

    Joined:
    Jul 25, 2012
    Messages:
    673
    Likes Received:
    1,244
    If those "certain links" has a rel attribute assigned to it, then yeah it's possible to modify the code to open only that links but I guess it's not possible especially in the Wordpress environment.
     
    • Thanks Thanks x 1
  7. tompots

    tompots Elite Member Premium Member

    Joined:
    Dec 11, 2011
    Messages:
    4,352
    Likes Received:
    3,955
    Gender:
    Male
    Occupation:
    Full Time Bot Developer
    Location:
    Professional Botters
    Home Page:
    Thanks, SmartMan you really are a SmartMan:)
     
    • Thanks Thanks x 1
    Last edited: Jun 27, 2013
  8. Ubaid Iqbal

    Ubaid Iqbal Registered Member

    Joined:
    Oct 31, 2012
    Messages:
    99
    Likes Received:
    15
    Occupation:
    Online Marketing Expert
    Location:
    BHW
    Home Page:
    thank you very much for your code i am looking for it.. thanks you
     
    • Thanks Thanks x 1