How to prevent links from being indexed in WordPress? And how do you open them? How to close links from indexing in WordPress Close from indexing 8 article.

How to prevent links from being indexed in WordPress? And how do you open them? How to close links from indexing in WordPress Close from indexing 8 article.

18.11.2021

Hello! Paul is with you. And in this article I want to tell you how you can "close" the links of your blog commentators from indexing.

Over the entire existence of this engine, tens of thousands of plugins have been created. Including those that affect how comments work. But in my case, I decided to go in a non-standard way - I made some changes to the "functions.php" file of my theme. And now, links to commentator sites are closed. Moreover, I see more than one way to hide them (but more on that later).

This link hiding method is suitable for any WP theme. But! If you are using a native theme - for example “ twentytwelve”, Then after updating it you will have to re-edit the file“ functions.php ”, which is inconvenient for the next updates. It is best to use this approach for a child theme (as in my case), or a custom theme.

An example implementation will be given based on the topic “ twentytwelve". To check, you can create a child theme or edit the current one, having previously made a backup (backup copy).

And so let's start, we go from the problem itself

We need to hide links to commentator sites. To determine which function is responsible for this, open the "comments.php" file of our theme, look for the function " wp_list_comments". As its parameter, we pass an array of values. The function with the "callback" index is responsible for building the list of comments. In our case, this is the function “ twentytwelve_comment". We just need it. We can find it in the “functions.php” file of our theme, at “/wp-content/themes/twentytwelve/functions.php”.

We open the file, look for the function “ twentytwelve_comment". Below is a part of the code from the file that interests us:

% 1 $ s% 2 $ s", get_comment_author_link (), // If current post author is also comment author, make it known visually. ($ comment-> user_id === $ post-> post_author)?" ". __ (" Post author "," twentytwelve ")."":" "); printf (" ", esc_url (get_comment_link ($ comment-> comment_ID)), get_comment_time (" c "), / * translators: 1: date, 2: time * / sprintf (__ ("% 1 $ s at% 2 $ s ", "twentytwelve"), get_comment_date (), get_comment_time ()));?>

Inside this function, we are looking for another - " get_comment_author_link". This f-I is responsible for displaying links to commentator sites. Now we will need to make a copy of this function and place it in the "functions.php" file but with a different name.

Open the file “/wp-includes/comment-template.php”, find the function “ get_comment_author_link", Copy it to the clipboard, and paste it into the" functions.php "file. We change its name, say to “ my_get_comment_author_link". Also, we change the name of the f-i " get_comment_author_link"In f-i" twentytwelve_comment"(The code example is given above) to" my_twentytwelve_comment". Are you confused? I hope no.

Now, we need to make some changes to our new function responsible for displaying a link to a comment. Below is an example of how this is done on my site:

Function my_get_comment_author_link ($ comment_ID = 0) ($ url = get_comment_author_url ($ comment_ID); $ author = get_comment_author ($ comment_ID); if (empty ($ url) || "http: //" == $ url) ($ return = $ author;) else ($ return = " $ author";) return apply_filters (" my_get_comment_author_link ", $ return, $ author, $ comment_ID);)

Please note - for links, we do not even use the "A" tag, but the "SPAN" tag, and the transition to the link is implemented using JavaScript functions " goto"Which we will have to insert into the theme's footer (this approach of hiding links was not invented by me, but was spied on somewhere).

Open the file "/wp-content/themes/twentytwelve/footer.php" and paste the following code:

between "" and "»

Also, do not forget to add styles to your theme for the "s-link" class so that the "SPAN" tag does not differ in design from the links of your theme. In my case, it would be like this:

Comments-area .bypostauthor cite span (position: initial;) .comments-area .bypostauthor cite span.s-link (font-weight: bold;) .comments-area span.s-link, .comments-area .bypostauthor cite span.s-link (cursor: pointer; font-size: 15px; color: # 444; padding-left: 0; margin-left: 0; background: white; border: none;) .comments-area span.s- link: hover (color: # 21759b; text-decoration: underline;) .comments-area .bypostauthor cite .s-author (position: absolute;)

That's all.

In one of the following articles, I will describe options for hiding links using PHP, JQuery and maybe something else, if I come up with it or spy somewhere.

Well, in I will describe how I managed to make friends with the plugin " Hide my dates"And the topic" twentytwelve»(If someone did not pay attention, the dates of comments of this topic together with this plugin are not displayed correctly).

If you have any other ideas for hiding links, you can write about them in the comments.

Thank you for the attention!

Greetings to all blog readers! Today I want to show you how to block links from indexing in blog comments. It is not difficult to do this even with minimal knowledge of php. If you have a lot of comments on your blog, then there is a great opportunity not to follow the links and miss a few open links, which is highly undesirable.

Of course, manually following the links in the comments is quite difficult, but installing an extra plugin because of this is also not an option. Therefore, I found, in my opinion, the most optimal solution in which everything happens automatically, and you do not need to manually track open links.

What exactly is going on? Links are closed with tags and ... This is done by pasting the php code snippet into your WordPress blog files comment-template.php and functions.php. Everything is simple, fast, reliable, and there is no need to install an extra plugin that will create additional load and additional queries to the database.

Thus, you can safely not edit every comment by closing links manually or deleting them - all links are automatically closed from indexing by Yandex and Google. How to do it in practice?

First, let's tackle the functions.php file located in your WordPress template directory. You need to insert the following code into it:

Function wp_noindex ($ comment) (return str_replace (" ", "", $ comment);) add_filter (" comment_text "," wp_noindex "); add_filter (" comment_text "," wp_noindex2 ");

The code must be inserted before the closing tag?>. Many do not know this and insert code snippets in the first place in the file, and then wonder why the site stopped working. So, I repeat - just before the closing tag?> At the end of the functions.php file!

Now you need to make some changes to the comment-template.php file. You will not find this file in the theme template folder - it is located in the wp-includes folder. This folder is located in the site directory - where the .htaccess, robots .txt and sitemap .xml files are located. So, in the file comment-template.php you need to find the code snippet:

$ return = "$ author";

And replace this fragment with the next one, which contains the noindex tags that Yandex works with.

$ return = " $ author";

Now the work can be considered finished - your comments are protected from open links, and do not pose any threat to the blog. Links will be closed from indexing from the main search engines - Yandex and Google. See you in the following publications.

In this article, we will consider such questions: “ How to prevent external links from indexing in WordPress? " and " How do I make links in the DoFollow blog comments?". The article is in the category of plugins, so we will do everything with their use.

But first you need to figure out why you need to open and close anything at all.

If the webmaster is not sure of the quality of the resource to which the link leads, then he closes it from indexing using the rel = "nofollow" attribute. The search engines Yandex and Google, seeing this value in the link, will not follow it, and also will not transfer weight.

And now a quite reasonable question: "Why then open links for indexing by search engines, make them Dofollow, if in this case weight will be transferred?"

Everything is quite simple here: those who are engaged in website promotion use Dofollow blog comments as an inexhaustible resource where you can get free external links. And links, as you know, have a certain impact on website promotion, albeit not as strong as before.

Webmasters use this for their own purposes, namely, the automatic filling of a site or blog with content (comments). And it also creates a kind of excitement on the blog, or rather its visibility, since messages are in fact left by spammers. Even so, when visitors see the crazy number of comments on a blog, they will have a certain amount of trust in the author. And it is possible that they will even add the page to bookmarks.

Plugin WP No External Links - close links from indexing

WP No External Links Plugin- an excellent WordPress plugin that allows not only to automatically add an attribute that blocks links from indexing to all links, but also to make an internal link from an external link using a redirect. This is indicated in the plugin settings as - link "masking". By the way, the same "masking" method is used to hide referral links.

The plugin can be downloaded and installed from the WordPress admin area, or from here: http://wordpress.org/plugins/wp-noexternallinks/

Let's move on to the settings:

Add rel = nofollow- adding a nofollow value for the rel attribute.

Add target = ”_ blank” Is a very useful option that adds target = ”_blank” to all external links. By enabling this option, all external links will open in a new window. This parameter is important for website optimization.

Add noindex tags- the expediency of using this parameter can be questioned, since rel = "nofollow" is quite enough for the search engines Yandex and Google to understand that there is no need to follow this link.

Do not mask links using redirects- my personal opinion, this function must be enabled. Search engines are constantly repeating: "The site should be natural!". What could be more natural than a simple external link?

And now the final touch: the plugin described above does not allow opening links in the author's name for indexing when submitting a comment.

This task will help to cope plugin - Do Follow... I will not write anything about its settings, for one simple reason - there are none. The plugin performs all its functions immediately after its activation. You can download everything from the same place - from the WP admin panel.

It's good when there are a lot of comments on the site or blog - this indicates the popularity of the resource, the author and the content posted. If not for one "but" - comments leave a huge number of outgoing links, along with comments, the weight of the site leaks, which undoubtedly negatively affects the promotion of the site in search engines. Therefore, you need to close links from indexing in the comments if you see this problem on your site.

For example, at the beginning of the year I realized that I also needed to get rid of duplicate pages, but, unfortunately, the ways that more tech-savvy colleagues share on the Internet are related to changes in the “functions.php” file. My actions in this file always break the site. I had to sit and wait by the sea for the weather along with a bunch of duplicates on the site.

And then one fine day a goldfish appeared, which fulfilled my desire, and helped, completely harmlessly and without wasting time on restoring the site, to close links from indexing. I'm kidding, of course, though ...

Unexpectedly for myself, I found information about the ARK HideCommentLinks plugin, which closes links to commentator sites and removes replytocom. The author of this plugin, Alexander Karataev, called it tiny, which means that the plugin is practically harmless for our sites. But the benefits from it are tangible. Download the plugin and add it to the site.

Close links in comments

The ARK HideCommentLinks plugin needs to be found in the console on the plugins page - "add new". After installation, you just need to activate it. If you have a caching plugin, then clear the cache and immediately see the plugin in action. After activating the plugin, you don't need to do anything!

Now, hovering over the author of the comment, we see a tooltip with the commentator's site address. After all, it would be completely wrong to completely remove links to the sites of commentators: sometimes guests give good advice, share their opinions, and often there is a desire to visit their sites.

And also, if you are aware of this topic, the plugin removes duplicates "replytocom" that appear when you click on the "Add comment" or "Reply" button. By the way, I haven't found a large number of these duplicates ... or could not find, which may well be :))

Moreover, now those who have widgets with the latest comments in the sidebar can rest assured. ARK HideCommentLinks closes links there too.

Of course, I will not be able to explain the principle of operation of this wonderful plugin in detail, the main thing is that I studied the reviews of its work and made the right decision for myself - to test the plugin in action on my website.

ARK HideCommentLinks Plugin: Top Benefits

I know in advance that questions may arise after installing the plugin on the site, so I recommend that you study all the comments to the article about this plugin on the site of the author Alexander Karataev, and, if necessary, ask him your questions.

On a note!

Note that after adding the plugin, an inscription appeared in the console: "The following plugins might cause (xml sitemaps) issues with Yoast WordPress SEO: Google XML Sitemaps". This meant that the ARK HideCommentLinks plugin was in conflict with Google XML Sitemaps. My site has Yoast WordPress SEO installed, which generates a sitemap on its own. It turns out that Yoast and Google XML Sitemaps are both trying to create the same sitemap.xml. And when installing ARK HideCommentLinks, there is a conflict. I decided to disable Google XML Sitemaps and the red mark disappeared, the plugin was activated without any problems.

Don't get rid of the comments

You know, I recently read that one site owner completely deleted all comments on his site, because he did not know how to get rid of external links in the comments ... If you are in the same situation, close to this, then the best way out for you would be to test the work of the plug-in on your website, and then already undertake surgical intervention.

Correct setting of site indexing is a very important circumstance! However, on the initial path of blogging / site, the problem is not approached correctly.

Yes Yes. I'm talking about robots.txt. This is not a completely correct approach, because robots is recommendatory in nature, and in our lifetime (we have enough experience) we have seen that a site closed from indexing got into the search results. But it’s okay, it’s more correct to solve this problem using the content = "noindex, nofollow" meta tags.

After reading this article, you yourself can easily become a "mother's programmer" and "make" your first code. Also, the article will be useful to those who need to close the page from indexing by other methods.

We will also teach you how to disable the user's browser from caching a single page using the nocache_headers () function. But it is, as a bonus.

Closing a separate page from indexing using php on wordpress

This is how the pages are closed in the robots.txt file.

What can I say here? And then, as luck would have it, with a high probability they will not get into the index, but if the search engine finds it necessary to index the page, then ... your dancing with a tambourine around robots will not lead to anything.

Just below the code, which in a wonderful way closes the pages of your choice from the eyes of robots: both google and yandex - every search engine obeys this order.

When you specify the desired page inside this code and open the source code of the page Ctrl + U, the coveted prohibition will become visible in the meta sections (at the very top):

Code to integrate into your header:

/ ** close the page from search engines - indexing ** /
function my_meta_robots () (
// close the page selectively
if (is_page (28)) // 28 record id
{
echo "". " "." \ n ";
}
}
add_action ("wp_head", "my_meta_robots");
/ ** close the page from search engines - indexing ** /

Pay attention only to this:

if (is_page (28))

The rest is irrelevant. You can safely delete comments in such // or such ** / brackets. By the way, based on this code, you can close mad categories or archives in wordpress.

if (is_archive () or is_category () or is_feed () or is_author ()

These “friends” usually create “parties” that create duplicate pages. And we know: duplicates are seo sin.

Here is code number two, which is easier to use (due to the fact that many do not know how to look at page id). This is an analogue of the one shown above and in a very wonderful way may come in handy in the future. So, put in your knowledge box.

/ *** CLOSING THE PAGES *** /
function echo_meta_mih_head () (
$ echo = false;
$ uri = $ _SERVER ["REQUEST_URI"];

if (mb_strstr ($ uri, "link in the format / razdel_name")) $ echo = true;
if (mb_strstr ($ uri, "link in the format / razdel_name")) $ echo = true;
if ($ echo) echo " ";
}
add_action ("wp_head", "echo_meta_mih_head");
/ *** CLOSING THE PAGES FROM SEARCHERS *** /

Bonus: how to disable caching of a single page or post?

Here we use the function: nocache_headers ()

The function actually removes the Last-Modified HTTP header (for PHP 5.3 and higher), or sets it to an empty value, if the version is lower than PHP 5.2 ..

Http header Last-modified - sends a signal to the client whether there have been changes on some page, informing it with an If-Modified-Since response with code 304

Headers of the type are set:

Cache-Control: no-cache, must-revalidate, max-age = 0
Pragma: no-cache

The code shown below (function workout) is important !! use before displaying any information on the user's screen, otherwise it will not work - which is natural!

if (is_single (28)) (

nocache_headers ();

That's all. I hope you received at least a little new information today. If you need high-quality contractors who can promote high-quality sites, then contact our friends (follow the link). They provide a free ad campaign introduction as a gift!

Best regards, Your Essence!

© 2021 hecc.ru - Computer technology news