且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法删除 wordpress 中的操作 noindex

更新时间:2023-12-05 23:51:34

使用 wp_robots WordPress 5.7.0 中引入的钩子,用于过滤机器人元标记输出.

Use the wp_robots hook introduced in WordPress 5.7.0 to filter its robots meta tag output.

示例函数:

add_filter( 'wp_robots', 'wp_robots_remove_noindex', 999 );

function wp_robots_remove_noindex( $robots ){
  
  //put any conditionals here to target certain pages
  if ( is_search() || is_archive(  ) || is_404(  ) ) {

    //set the index and noindex array items
    $robots[ 'index' ] = true;
    $robots[ 'noindex' ] = false;
  }

  return $robots;   
}

这将导致以下输出:<meta name='robots' content='index, follow'/>