Support » Fixing WordPress » target="_blank" for a page on menu?

  • Resolved Bhavadasa

    (@bhavadasa)


    I’ve created a discussions board, and a page on the menu with the same address. It works well. However, rather than loading in a new tab (keeping the webpage open), it loads in the same tab.

    Is there a php, or somewhere I can add target=”_blank” to the address?

    Thanks!

Viewing 15 replies - 1 through 15 (of 55 total)
  • Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Ooops misread, I’ll post something more sensible

    Yikes. Lost me. Can you give me a little direction?

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    There should be a section either within the PHP that’s constructing the hyperlink, which you can add target="_blank" to the link.

    Do you know which file holds this?

    No, that’s part of my problem. I’ve scanned a number of php files, but can’t find that (discussions) address anywhere.

    Years ago, I had a website that I was able to find the menu with “Home” in it. Then next to it (for another page) I simply added the url with target=”_blank” — and it worked. But, I’m not having such luck now.

    On “View Page Source” I find the below code . (it appears differently when posted here). But where do I find it, to edit?

    <body>
    <div id=”page2″>
    <div id=”header”>
    <div class=”logo_resize”>
    <div class=”logo”>
    <h1>
    Saranagati Village Inc.
    </h1>
    <small class=”slogan”>
    The Official Website of the Board of Directors for SVHI </small></div>
    <!– /logo–>
    <div class=”topnav”>
    <ul class=”menusm”>
    <li class=”page_item page-item-27 current_page_item”>Home
    <li class=”page_item page-item-32″>Blog
    <li class=”page_item page-item-136″>Discussions
    <li class=”page_item page-item-126″>Membership
    <li class=”page_item page-item-40″>Contact

    </div>
    <!–/topnav –>
    </div>

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Okay, in that code (above),
    could you repost it in the code tags (otherwise the hyperlink wont show up properly, as you can see there’s no <a> tags).

    Then could you say which hyperlink you want to have a target blank?

    This system isn’t allowing the coding to post as it appears in “view page source”. I’ll try the hyperlink….

    It’s line #136:> Discussions:

    a href=”http://www.saranagativillage.com/discussions/”

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Are you using the

    code

    button (just above this text box when replying) to wrap your code?

    This is the “index” page, right? Where do I find it as it appears “view page source”? I’ve looked in the “index.php, but no sign of it. Hmmm…

    Using the code button? No.

    Sorry about that!

    <body>
    <div id="page2">
    <div id="header">
      <div class="logo_resize">
        <div class="logo">
          <h1><a href="http://www.saranagativillage.com" title="Saranagati Village Inc. - The Official Website of the Board of Directors for SVHI">
            Saranagati Village Inc.        </a></h1>
          <small class="slogan">
          The Official Website of the Board of Directors for SVHI      </small></div>
        <!-- /logo-->
        <div class="topnav">
          <ul class="menusm">
            <li class="page_item page-item-27 current_page_item"><a href="http://www.saranagativillage.com/">Home</a>
    <li class="page_item page-item-32"><a href="http://www.saranagativillage.com/blog/">Blog</a>
    <li class="page_item page-item-136"><a href="http://www.saranagativillage.com/discussions/">Discussions</a>
    <li class="page_item page-item-126"><a href="http://www.saranagativillage.com/membership/">Membership</a>
    <li class="page_item page-item-40"><a href="http://www.saranagativillage.com/contact/">Contact</a>
    
        </div>
        <!--/topnav -->
      </div>
    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    Instead of fishing through the page for it, you could use jQuery to add the target of blank to your menu item.

    You said you want it for Discussions?
    Assuming the Discussions link will start with http://

    $('.topnav a[href^="http://"]').attr('target','_blank');

    Ok. Sorry, this is a little bit above me…

    I don’t know how to use jQuery
    Where would I find that specific code?
    I assume that I would insert the address after “http://. Correct?

    Moderator Andrew Nevins

    (@anevins)

    Forum moderator

    In the admin panel,
    Go to
    – Appearance
    – Editor

    on the right hand side, look at Templates section
    – find footer.php
    – click on footer

    – paste this above </body>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
    $('.topnav a[href^="http://"]').attr('target','_blank');
    </script>

    ——

    I assume that I would insert the address after “http://. Correct?

    Correct but only in the navigation menu. Are there some links (that start with http) you don’t want to add target of blank?

Viewing 15 replies - 1 through 15 (of 55 total)
  • The topic ‘target="_blank" for a page on menu?’ is closed to new replies.