Use External Permalinks -- won't open in new window

I'm using the Autoblog "Use External Permalinks" add-on so that my post titles automatically link to the original source. The link is fine--I was expecting to hard-code that part, but this couldn't be easier :slight_smile:

However, it is imperative that the original source open in a new browser window, but that doesn't seem to be working. I have the "Open links in popup" add-on activated, and under the feed settings, in the Open Link in Popup section, the checkbox for "Do you want to turn off this feature" is NOT checked.

Am I missing something? Or does this plugin only affect the original source link that would appear in the post body, and not the post title? If it doesn't work on the post title link to the original source, I assume I'll need to modify my theme to hard-code an open in new browser window?

  • Hoang Ngo
    • Code Slayer

    Hi there @dt,

    I hope you are well today.

    For the open title in new tab, I'm afraid we will need to manually add a small js code for that because this mostly rely on theme, not from wordpress function output.

    Example here is the code to output the post title from the 2012 theme
    <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
    As you can see, there's only the filter for the title text, or the url, not the anchor tag. So, to make this working, please add this code to your theme functions.php or use mu-plugins

    add_action('wp_footer', 'open_in_newtab');
    function open_in_newtab()
    {
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function ($) {
                $('h2.postLink a').attr('target', '_blank');
            })
        </script>
    <?php
    }

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang Ngo

    • dt
      • New Recruit

      So your fix worked partially. I noticed this morning that it only works if the post title is clicked. Works perfectly in that case. However, on posts that have a featured image that show up just above the post title, it doesn't work.

      If you go to http://bit.ly/1vRdEG2, you can see what I'm referring to on the site. Click any of the post titles and it works fine. Click any of the posts that show an image just above the post title, and you'll see it opens the article in the current window.

      How might I fix this?

  • Hoang Ngo
    • Code Slayer

    Hi @dt,

    I hope you are well today and I'm sorry for the delay.

    Sorry for the missing, I don't know we have the thumbnail there too :slight_smile:, here is the code fix

    add_action('wp_footer', 'open_in_newtab');
    function open_in_newtab()
    {
        ?>
        <script type="text/javascript">
            jQuery(document).ready(function ($) {
                $('h2.postLink a, .thumbLink').attr('target', '_blank');
            })
        </script>
    <?php
    }

    Please replace the old code with this one, it should work :slight_smile:

    If you have any issues please don't hesitate to let us know so we can assist

    Best regards,
    Hoang Ngo

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.