Only today a customer asked us for help in adding the X-Robots-Tag HTTP header for all that content which had previously been marked as noindex in the WordPress plugin Rank Math SEO – AI SEO Tools to Dominate SEO Rankings.

Although we understand that this is something the Rank Math SEO plugin itself should handle directly from its source code, it turns out that this is not the case.

While Rank Math SEO adds the meta tag <meta name="robots" content="nofollow, noindex"> to all content marked as noindex in its settings or directly in its metabox, it does not do the same with the X-Robots-Tag HTTP header, and we understand that this is not right, since for them it is really simple to add it.

We have referred the customer to Rank Math SEO’s technical support so that they add this feature to their code, but while they do or do not add it, we are sharing with you the solution we have created and that we have asked them to add.

Solution

The PHP code we propose has to be added to the functions.php file of the child theme, and it has to be done on its first line, since otherwise it will give you problems. Specifically, this is the function that has to be added:

Copy to clipboard

Line 1 is the one that will give you problems if it is not added at the beginning of the functions.php file; the apg_add_x_robots_tag function itself you can add wherever you like within that same file, and it will not cause you any problem.

The way the function works is very simple: it obtains information from the Rank Math SEO plugin’s settings and, depending on it, adds the header or not, so that it only adds it if the content has been marked as noindex, which is what we are interested in adding.

How can I see whether it works or not?

You can do it directly from your favourite web browser with the Web Inspector tool, reviewing the document headers where this new header will or will not appear, or by installing an extension such as Robots Exclusion Checker, which shows you visually the status of the page you are viewing in the robots.txt file, the robots meta tag, the X-Robots-Tag header and the Canonical tag.

Conclusion

We hope you find this code useful; it is easily replicable for other WordPress plugins such as Yoast SEO, with which you would have to play with the WPSEO_Meta::get_value() function to obtain a result identical to the one proposed. And if you need help, you know you have our Technical support to help you.

Related posts

Comments

Suscríbete
Notificar de
0 Comments
Más antiguos
Más recientes Más votados

In this post

Products and services

Latest posts

Latest comments

Subscribe!

Lista de correos de APG

DATA PROTECTION: In accordance with data protection regulations, we provide you with the following processing information: (+)

  • Responsible: Art Project Group.
  • Treatment purposes: to respond to queries or any type of request made by the user through any of the forms of contact that are made available on the website. Sending communications about products or services (with your consent).
  • Your rights: access, rectification, portability, deletion, limitation and opposition. More information about the treatment in the Privacy Policy.

What we post on !

Se ha publicado #WooCommerce 11.2.2: actualización de seguridad que refuerza las API REST y Store, mejora la validación de CSV y corrige problemas en pagos y pedidos. Incluye cambios en la base de datos.

¡Actualiza cuanto antes!

13 hours ago