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.