How do I make the permalinks for post titles open in a new browser window

Contents

[ hide ]

    For more how-tos and advice, return to How Do I …?

    Q: How do I make the permalinks for post titles open in a new browser window?

    A. This is easily done by editing your WordPress template files to give the post permalinks a target="_blank" attribute. (You can edit template files directly from the WordPress administrative interface using Appearance –> Theme Editor, or you can edit them in a text editor on your own computer and upload them to your theme directory.)

    The Templates section of the Documentation Wiki documents the template tags that FeedWordPress provides when it is activated; the only one that you may need to use here, though, is is_syndicated(), if you want syndicated posts to open in new windows but want local posts to open in the same window. To do that, edit your Post Loop in the Main Index Template (index.php), Archive (archive.php), and Search Results (search.php) template files. Find the section that displays the headline for each post; it should look something like this (it will differ a bit from theme to theme):

        <?php while (have_posts()) : the_post(); ?>
    
    <div <?php post_class() ?>>
    <h3 id="post-<?php the_ID(); ?>"><a href="<?php
    the_permalink() ?>" rel="bookmark" title="Permanent
    Link to <?php the_title_attribute(); ?>"><?php
    the_title(); ?></a></h3>
    

    Now edit that so that the <a href="..."> element includes the attribute target="_blank".

        <?php while (have_posts()) : the_post(); ?>
    
    <div <?php post_class() ?>>
    <h3 id="post-<?php the_ID(); ?>"><a href="<?php
    the_permalink() ?>" rel="bookmark" title="Permanent
    Link to <?php the_title_attribute(); ?>"
    target="_blank"><?php the_title(); ?></a></h3>
    

    Or, if you want to make it so that syndicated posts open in new windows, but local posts do not:

        <?php while (have_posts()) : the_post(); ?>
    
    <div <?php post_class() ?>>
    <h3 id="post-<?php the_ID(); ?>"><a href="<?php
    the_permalink() ?>" rel="bookmark" title="Permanent
    Link to <?php the_title_attribute(); ?>" <?php if
    (is_syndicated()): ?>target="_blank"<?php endif;
    ?>><?php the_title(); ?></a></h3>
    

    Save the changes to your template file and reload. Now the permalinks behind each post’s headline should open in a new window.

    Does that answer your question? If not, use the Talk page to comment on this post or contact me by e-mail for help. Be sure to describe what you are trying to do, and the problems you are running into, with as much detail as possible.

    For more how-tos and advice, return to How Do I …?

    This page is a Wiki! Log in or register an account to edit.

    8 thoughts on “How do I make the permalinks for post titles open in a new browser window

      • For the atahualpa template In /wp-content/themes/atahualpa/functions/bfa_post_parts.php change the code like this:

        <a href="<?php the_permalink() ?>" rel="bookmark"
        title="Permanent Link to <?php the_title(); ?>"
        target="_blank"> <?php } 
        
    1. How can we do the target=”_blank with the templates like themes/atahualpa ? I suppose it will be better to put an add-on ? But how to do?

    2. I got a problem. When I add target=”_blank” it will only works when I set Permalinks point to: the local copy on this website

      But the feed only load’s a part of the original article, so only a part of the article will be saved on my own website.

      When I point the permalinks to: the copy on the original website. The website visitors are able to read the whole article, but then the article will no be load in a new page.

      What do I have to change to get the article load in a new page when Permalinks point to: the copy on the original website?

      I hope that someone can help me out.

    3. Hi,

      I believe that there is an error:

           <?php while (have_posts()) : the_post(); ?>
      
          <div <?php post_class() ?>>
              <h3 id="post-<?php the_ID(); ?>"><a href="<?php
              the_permalink() ?>" rel="bookmark" title="Permanent 
              Link to <?php the_title_attribute(); ?>" <?php if 
              (is_syndicated()): ?>target="_blank"<?php endif; 
              ?>><?php the_title(); ?></a></h3>
      

      should be

           <?php while (have_posts()) : the_post(); ?>
              <div <?php post_class() ?>>
              <h3 id="post-<?php the_ID(); ?>"><a href="<?php
              the_permalink() ?>" rel="bookmark" title="Permanent 
              Link to <?php the_title_attribute(); ?>" <?php if 
              (is_syndicated()): ?>target="_blank"<?php endif; 
              ?><?php the_title(); ?></a></h3>
      

      You had one ‘>’ too much. Thanks a lot for the great tip you gave us. I have a working feeds page.

      Gershon

    4. Hello,

      Thank you for the wonderful intitianve.

      One issue I found was that when you enable your second code: < ?php while (have_posts()) : the_post(); ?>

          <div <?php post_class() ?>>
              <h3 id="post-<?php the_ID(); ?>"><a href="<?php
              the_permalink() ?>" rel="bookmark" title="Permanent 
              Link to <?php the_title_attribute(); ?>" <?php if 
              (is_syndicated()): ?>target="_blank"<?php endif; 
              ?>><?php the_title(); ?></a></h3>
      

      Every link will be opened in a new window, even-though the code has an if-case.

      Gershon

    5. I’ve added the target=”_blank” tag to my permanent link. Clicking the permanent link opens original article in a new window. That’s cool.

      The problem is that any link on the title bar in any theme will open the permanent link in a new window. For example, if there’s a link to add a comment at the end of the title bar, clicking it will open the original article in a new window with a #comment tag on the end of the URL. Could this be a teme issue or is it related to hacking the title link code for feedwordpress?

    6. My template also used this post loop in the following file.

      category.php

      So be sure to include it in that file also, as well as index.php search.php and archive.php

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>