WordPress.org

Ready to get started?Download WordPress

Forums

Atahualpa
Menu link new window/tab (2 posts)

  1. steeleweed
    Member
    Posted 4 months ago #

    Is there a way to make the menu links open new new window/tab? Basically adding target="_blank" to the link.

    Ideally via the HTML/CSS customizations.

    Thanks,
    RayS

  2. CrouchingBruin
    Member
    Posted 4 months ago #

    Very easy to do.

    Use a web debugging tool like Firebug or Chrome Developer Tools and inspect the menu item (or you can even do a view source and look for the menu item).

    The list item (< li >) element that creates the menu item will have an ID that looks like menu-item-###, where ### is a unique numeric identifier. Let's say, for example, that the menu item that you want to modify has an ID of menu-item-123.

    Go to Appearance > Atahualpa Options > Add HTML/CSS Inserts, and copy this JQuery code into the HTML Inserts: Body Bottom field:

    <script>
    jQuery(document).ready(function($){
       $("#menu-item-123 a").attr('target', '_blank');
    });
    </script>

    Click the big, green Save changes button.

    It's basically one line of JQuery code that executes when the document has finished loading (the document ready function). The first part is the selector which targets the anchor tag belonging to the menu item that you want to modify. The attr method sets the attribute that's listed in the first parameter of the function to the value listed in the second parameter of the function. So it's basically saying "set the target attribute of the link belonging to the element with ID menu-item-123 to _blank."

Reply

You must log in to post.

About this Theme

About this Topic

Tags