I
I
Igor Vasilenko2021-08-16 18:51:04
WordPress
Igor Vasilenko, 2021-08-16 18:51:04

How to remove robots meta tag?

By default, Wordpress inserts this meta tag into all pages of the site , but I need to insert this meta tag on the first spread of the shop

woocomerce page

and insert meta on all pagination pages .

I did this in the output area of ​​the Yoast plugin .
the question is, can the first one be deleted altogether, the one that is displayed by wordpress?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Zolin, 2021-08-16
@artzolin

The function is responsible for displaying this meta tag wp_robots(). Yoast, with the help of a filter, can add its own tags to it. This is the correct way to work with the robots meta tag. If you have two of them, then you do not need to delete it, but look for the second one.
You can control the operation of this tag using the filter of the same name wp_robots. For example, the code below will add noindex to archived pages with no posts.

add_filter( 'wp_robots', 'custom_wp_robots' );
function custom_wp_robots( $robots ) {

  if ( is_archive() && !have_posts() ) {
    $robots['noindex'] = true;
    $robots['nofollow'] = true;
  }
  
  return $robots;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question