Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add below if using All In One SEO plugin
- // This is to remove meta robots tags on the following pages:
- /*
- https://www.sailboatrc.com/product-category/electronic/page/3/
- https://www.sailboatrc.com/product-category/electronic/page/2/
- https://www.sailboatrc.com/product-category/addon/page/3/
- https://www.sailboatrc.com/product-category/addon/page/2
- */
- function custom_aioseo_disable_meta_robots_on_paginated_category_urls( $robots ) {
- if ( is_paged() && is_product_category() ) {
- $category = get_queried_object();
- $slug = isset( $category->slug ) ? $category->slug : '';
- // Define the slugs for which you want to remove the robots meta tag
- $target_slugs = array( 'electronic', 'addon' );
- if ( in_array( $slug, $target_slugs ) ) {
- // Return an empty robots array to remove the tag
- return [];
- }
- }
- return $robots;
- }
- add_filter( 'aioseo_robots_meta', 'custom_aioseo_disable_meta_robots_on_paginated_category_urls' );
- // While with the codes ABOVE (to avoid duplicate meta robots tag)
- // forcely add meta robots on specified pages to index them
- function custom_add_robots_meta_for_specific_paginated_urls() {
- if ( is_paged() && is_product_category() ) {
- $category = get_queried_object();
- $slug = isset( $category->slug ) ? $category->slug : '';
- $paged = get_query_var( 'paged' );
- // Target only specific slug + page combinations
- $allowed_combinations = array(
- 'electronic' => array( 2, 3 ),
- 'addon' => array( 2, 3 ),
- );
- if ( isset( $allowed_combinations[ $slug ] ) && in_array( $paged, $allowed_combinations[ $slug ] ) ) {
- echo '<meta name="robots" content="index,follow">' . "\n";
- }
- }
- }
- add_action( 'wp_head', 'custom_add_robots_meta_for_specific_paginated_urls', 5 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement