在wordpress中查找并替换html标头标签

Is it possible to find and replace html tags in header with a function?

Here's what I need to do:

I'm using wpseo plugin and I set default to no index subpages of archives.

But I have some categories where I would like to have sub-pages indexed and the plugin adds the noindex tag to them all.

Therefore, I need to find this tag <meta name="robots" content="noindex,follow"> and replace it with <meta name="robots" content="index,follow"> ONLY on those especific categories.

ie:

// First I need to get the url
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];

// Now I will check if I'm on category and if current url has the word "page"
// This way, I know I'm on the next pages of the category

if (is_category(array(561) &&  strpos($url,'page') !== false)) {
// If I'm on paged content of category 561

    => FIND THIS: <meta name="robots" content="noindex,follow">
    => REPLACE WITH: <meta name="robots" content="index,follow">';

How can I do this?

you can hook into the WP SEO 'wpseo_robots' hook like this:

<?php
// add the filter using an anonymous function
add_filter( 'wpseo_robots', function ( $robotsstr ) {

  if ( is_category(array(561) ) &&  ! is_paged() ) {

    $robotsstr = '<meta name="robots" content="index,follow">';

  }

  return $robotsstr;

}, 10, 1 );

...or more "traditionally like this:

function SO_39730632_amend_robots ( $robotsstr ) {

  if ( is_category(array(561) ) &&  ! is_paged() ) {

    $robotsstr = '<meta name="robots" content="index,follow">';

  }

  return $robotsstr;

}

add_filter( 'wpseo_robots', 'SO_39730632_amend_robots', 10, 1 );

The is_paged() function should take care of the pagination check for you.