How to open each Wordpress post in new tab/window?

2019-02-20 18:26发布

问题:

I have one wordpress blog whose home page is showing a list of 10 latest posts.

Now whenever I am going to click on any post title, a new post will open in the same tab, but here I want to let open it in a new tab. So, how can I do that?

回答1:

edit your theme

/wp-content/themes/your-theme-name/loop.php

look for post link eg...

<a href="<?php the_permalink(); ?>" class="read_more_link" ><?php echo __('Read more &raquo;'

add target="_blank" attribute

<a href="<?php the_permalink(); ?>" target="_blank" class="read_more_link" ><?php echo __(

each Wordpress theme have a different html. just search for.. href="<?php the_permalink(); ?>" this is permalink of each post



回答2:

There are different templates for each and every theme in Wordpress.

Try finding

    < a href="<?php the_permalink(); ?>"...............><?php the_title(); ?></a>    

Press F3 and search for this code like the_title();. Normally these type of codes are founded in templates like

single.php, content.php, loop.php, content-single.php

Just add a target="_blank" in that code.

For example :

<a href="<?php the_permalink(); ?>" target="_blank".....><?php the_title(); ?></a>


回答3:

Open your relevant php file(s), ie. front-page.php, home.php... and just add target="_blank" in your title <a>.



回答4:

I found this code on http://www.wpcodesnippet.com/open-external-links-new-window/ and it worked like a charm for me. Just add it to your footer.php.   

 <script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function($) {
            $('a').each(function() {
                var a = new RegExp('/' + window.location.host + '/');
                if(!a.test(this.href)) {
                    $(this).click(function(event) {
                        event.preventDefault();
                        event.stopPropagation();
                        window.open(this.href, '_blank');
                    });
                }
            });
        });
        //]]>
    </script>


回答5:

One convenient fix is to set the banner to open a new tab at the page after updating page at the notice: Page updated. View page link. Add the target="_blank" after the <a call. At file /wp-admin/edit-form-advanced.php change the line 136 as shown in the graphic. This was implemented at WordPress v4.9.8. When WP is updated the fix may need to be done again.



回答6:

Unless your hosting it yourself I don't think you can, otherwise just change your links to:

<a href="your url" target="_blank">blah</a>