Noindex category fillter pages

#920714
  • Resolved Babrikov
    Rank Math free

    Hello,

    I have a categories for example https://www.bioslunceluna.com/k/canabidiol/

    And i wanna make all filter pages to be noindexed (all pages that include the following filters)

    ?orderby=popularity
    ?orderby=rating
    ?orderby=date
    ?orderby=price
    ?orderby=price-desc

    I am using the following code in function.php, but its not working

    // Noindex for filter queries
    add_filter( ‘rank_math/frontend/robots’, function( $robots ) {
    // Вземаме текущия URL
    $url = home_url( $_SERVER[‘REQUEST_URI’] );

    // Проверяваме дали URL-то съдържа параметър ‘orderby’ с една от зададените стойности
    if ( isset( $_GET[‘orderby’] ) && in_array( $_GET[‘orderby’], [‘popularity’, ‘rating’, ‘date’, ‘price’, ‘price-desc’] ) ) {
    // Диагностика: отпечатваме текущия URL и стойността на ‘orderby’
    error_log( ‘Noindex applied for: ‘ . $url );

    // Задаваме noindex за тези филтрирани URL-та
    $robots[‘noindex’] = true;
    $robots[‘follow’] = ‘follow’; // Можеш да оставиш следенето включено
    }

    return $robots;
    });

    Can you help me please.

    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    You can use this code to set those filtered URLs to noindex:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	$url = home_url( $_SERVER['REQUEST_URI'] );
    	if (strpos($url,'order_by=') !== false )) {
                    $robots['index'] = 'noindex';
                    $robots['follow'] = 'nofollow';
    	        return $robots;
            }
    	return $robots;
    });

    Here’s how you can add a filter/hook to your WordPress site:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps.

    Babrikov
    Rank Math free

    Hello,

    I,ve tried but its not working,

    Example of my filtreted category – https://www.bioslunceluna.com/k/canabidiol/cbd-maslo/?orderby=date

    Best Regards

    Hello,

    Please replace the condition in the filter code with the following one:

    if (strpos($url,'orderby=') !== false ))
    

    Let us know how it goes. Looking forward to helping you.

    Thank you.

    Babrikov
    Rank Math free

    Thank you, now its working

    Hello,

    We are glad to hear that this issue has been resolved. Thank you for letting us know. This ticket will be closed now, but you can always open a new one if you have any other questions or concerns. We are here to help you with anything related to Rank Math.

    We appreciate your patience and cooperation throughout this process.

    Thank you for choosing Rank Math.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Noindex category fillter pages’ is closed to new replies.