Opening a tab in a new html window. How to open a link in a new window

The expression open links in new window in this article means that links will open in a new tab or window, depending on your browser settings. In any case, it is assumed that the page from which the link was clicked will remain open.

Why might this be needed? Visitor in this moment be on your website, and there is an external link in the article or on the website page. If this link is of interest to the visitor in some way, then after clicking on such an external link he will be taken to another site.

On another site, he may open several more pages and after that it will be difficult for him to get to your site again. He didn’t finish reading your article, and not every computer user will immediately understand how to get to your site again, because people different preparation and it is not always clear to beginners what to do in this case.

In the browser, you can click on the back button, but the visitor could close the window on another site altogether, but he wanted to finish reading your article, and not the article that he accidentally landed on external link.

You can open a link in a new browser tab by manually inserting the “target” attribute with the tag value “_blank” into each such link . In HTML it will look like this - target=”_blank”. But there can be a lot of such links, and you won’t always remember which external links have not yet had this attribute inserted.

When adding new links and images in an article, in the WordPress admin panel, in the text editor, there are corresponding items, the activation of which allows you to open the added links and images in a new window.

There are several ways to make links open in a new window. In this article I will describe only those methods that worked on my site.

Some methods did not work correctly on my site in the previous template, so I will not talk about them. In particular, it was displayed incorrectly home page in a way that requires connection JavaScript libraries- jQuery. Additionally, this method would not work if JavaScript was disabled.

How to open a link in a new window

In order to open absolutely all links on the site in new windows or tabs, you will need to insert special code to the file “Header (header.php)”.

To insert this code you need to enter " WordPress Admin Panel» => « Appearance" => "Editor" => "Header (header.php)".

In the file “Header (header.php)” between the and tags you need to insert the following code right before the closing tag:

This setting for opening pages in a new window or tab does not seem very convenient to me, because this opens many windows or tabs in the browser. But, I know that for some, on the contrary, it will be convenient to be able to open external and internal links on their site in this way.

Target Blank In Posts And Comments Plugin

The Target Blank In Posts And Comments plugin helps you open links in comments and posts in a new window without affecting other internal links on the site.

You can download the Target Blank In Posts And Comments plugin from here.

This plugin hasn't been updated for a long time, but it works well on latest version WordPress engine, and copes with his duties perfectly. It also worked on my site for some time.

To install the Target Blank In Posts And Comments plugin, you will need to log in to the “WordPress Admin Panel” => “Plugins” => “Add New” => “Install Plugins” => “Upload”. After downloading, the plugin needs to be installed and activated.

The Target Blank In Posts And Comments plugin does not require any settings and starts working immediately after its activation.

Using this plugin will allow you to return visitors to your site who clicked on an external link from your site. After all, it often happens that a visitor has been looking for a long time necessary information, and then suddenly clicked on a link that interested him from a comment or article, then went somewhere else, and thus the visitor often cannot find the site from which he originally came.

The Target Blank In Posts And Comments plugin does its job well, allowing you to retain and return visitors to your site.

Opening a comment link in a new window

If you need to open links with comments without the help of a plugin, then this can be done after changing the corresponding code. Changes will need to be made in the code of the “comment-template.php” file, which is located in the “wp-includes” folder.

To do this, you will need to connect to your site via FTP connection using programs such as FileZilla or Total Commander. This can also be done using file manager, which is located in the Control Panel of your hosting.

The file “comment-template.php” is located approximately along this path - domains/name of your site/public_htlm/wp-includes/comment-template.php.

Attention! Before changing the “comment-template.php” file, you must make a copy of it. In case of problems, after changing the file code, your site may stop working normal mode. In this case, you will have to replace the file you changed with the saved one. original copy this file.

Happened to me similar case, and I had to rollback the site to working condition by using technical support my hosting. I didn't save a copy original file, made incorrect changes to the file code, and after that my site stopped being displayed on the Internet for some time.

This would not have happened if I had made a copy of the file before changing it, because I would have immediately replaced the broken one with a working one.

You will need to copy the “comment-template.php” file to your computer and save it. You need to make a copy of the saved file and make changes in the file code by opening it using text Notepad editor++. You can open the file in Notepad, but it will be very difficult to find in Notepad required lines code to change it.

Next you should add the line starting with $return = ”