Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Make Drop Down Menu Links Open in New Page


  • Doug
    Participant

    @brainiacwebdesigns

    How can i make the drop down menu links seen at http://www.TheSoldiersNetwork,com , under Useful Links, open up in a new tab or page when clicked instead of navigating away from my website in the same page? i assume its just an easy edit, just gotta find the page to edit. Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

  • pcwriter
    Participant

    @pcwriter

    @BrainiacWebDesigns

    No, it’s not a simple edit on any specific page because those are links you’ve added to a WP Custom Menu. As they are stored in the database and called via the wp_nav_menu function, they won’t be visible in any file.

    But it looks like it can be done with jquery. 🙂 Assuming you want to continue using WP Custom Menus for those links in your navigation (rather than hard-coding them into your header.php file), you’d need to target only those links contained within the specific <li> item in the menu. (According to Firebug, that would be .sf-menu li#menu-item-174 li a. Note that if you modify the custom menu after applying any rules to that specific li#, you may need to adjust the the following code ‘cuz the li# may change.)

    jQuery(document).ready(function($) {
    $(".sf-menu li#menu-item-174 li a[href^='http://']").attr("target","_blank");
    });
    

    To see how it’s done, see the 2nd example snippet on this page: http://css-tricks.com/snippets/jquery/open-external-links-in-new-window/
    …as well as wp_enqueue_script: https://codex.wordpress.org/Function_Reference/wp_enqueue_script

    Another way would be to use register_nav_menu to create an additional Theme Location under WP Custom Menus where you can assign a special menu coded to open all links in new windows. See the WP codex here for that: https://codex.wordpress.org/Function_Reference/register_nav_menu

    Hope this helps 🙂
    …and have fun!


    Doug
    Participant

    @brainiacwebdesigns

    u my friend, are a genius. im gonna tackle this right now, thanks buddy


    pcwriter
    Participant

    @pcwriter

    @BrainiacWebDesigns

    This code would probably be a lot easier still. You don’t have to worry about any changes to your custom menus because it targets all external links in your main navigation, no matter where they may be in the menu.

    jQuery(document).ready(function($) {
    $('.sf-menu a:not([href^="http://thesoldiersnetwork.com"]):not([href^="#"]):not([href^="/"])').addClass('external').attr({ target: "_blank" });
    });

    EDIT: forgot to include.attr({ target: "_blank" }) in the above code… it’s there now 😉


    Doug
    Participant

    @brainiacwebdesigns

    actually i found this plugin…

    Open external links in a new window

    did exactly what i needed and more in fact! thanks a lot for ur help tho pcwriter!


    pcwriter
    Participant

    @pcwriter

    You’re welcome, glad things worked out :-)


    Doug
    Participant

    @brainiacwebdesigns

    yes sir youre very helpful and its appreciated

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] Make Drop Down Menu Links Open in New Page’ is closed to new replies.
Skip to toolbar