Advertisement
sierre

Forcely Index the noindex pages - meta tags

May 15th, 2025 (edited)
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.80 KB | None | 0 0
  1. // Add below if using All In One SEO plugin
  2. // This is to remove meta robots tags on the following pages:
  3. /*
  4. https://www.sailboatrc.com/product-category/electronic/page/3/
  5. https://www.sailboatrc.com/product-category/electronic/page/2/
  6. https://www.sailboatrc.com/product-category/addon/page/3/
  7. https://www.sailboatrc.com/product-category/addon/page/2
  8. */
  9. function custom_aioseo_disable_meta_robots_on_paginated_category_urls( $robots ) {
  10.     if ( is_paged() && is_product_category() ) {
  11.         $category = get_queried_object();
  12.         $slug = isset( $category->slug ) ? $category->slug : '';
  13.  
  14.         // Define the slugs for which you want to remove the robots meta tag
  15.         $target_slugs = array( 'electronic', 'addon' );
  16.  
  17.         if ( in_array( $slug, $target_slugs ) ) {
  18.             // Return an empty robots array to remove the tag
  19.             return [];
  20.         }
  21.     }
  22.  
  23.     return $robots;
  24. }
  25. add_filter( 'aioseo_robots_meta', 'custom_aioseo_disable_meta_robots_on_paginated_category_urls' );
  26.  
  27. // While with the codes ABOVE (to avoid duplicate meta robots tag)
  28. // forcely add meta robots on specified pages to index them
  29. function custom_add_robots_meta_for_specific_paginated_urls() {
  30.     if ( is_paged() && is_product_category() ) {
  31.         $category = get_queried_object();
  32.         $slug     = isset( $category->slug ) ? $category->slug : '';
  33.         $paged    = get_query_var( 'paged' );
  34.  
  35.         // Target only specific slug + page combinations
  36.         $allowed_combinations = array(
  37.             'electronic' => array( 2, 3 ),
  38.             'addon'      => array( 2, 3 ),
  39.         );
  40.  
  41.         if ( isset( $allowed_combinations[ $slug ] ) && in_array( $paged, $allowed_combinations[ $slug ] ) ) {
  42.             echo '<meta name="robots" content="index,follow">' . "\n";
  43.         }
  44.     }
  45. }
  46. add_action( 'wp_head', 'custom_add_robots_meta_for_specific_paginated_urls', 5 );
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement