• Resolved virtual03

    (@virtual03)


    Hello RankMath Support,

    i have a request, i would like to set the widget “woocommerce_product_categories” to no index. i have created a code for this. can you tell me if it can work to not index the widget but the rest of the page?

    function exclude_widget_from_indexing() {
    $widget_ids_to_exclude = array( ‘woocommerce_product_categories’ );
    $current_widget_id = get_query_var( ‘widget’ );

    if ( in_array( $current_widget_id, $widget_ids_to_exclude ) ) {
        echo '<meta name="robots" content="noindex,nofollow" />';
    }

    }
    add_action( ‘wp_head’, ‘exclude_widget_from_indexing’ );

    best regards
    Daniel

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @virtual03,

    Thank you so much for getting in touch.

    Please note that WordPress widgets don’t have robots meta in them as they are meant to be inserted into a page content where the robots meta is controlled.

    With that said, here’s the filter code on how you would control our plugin’s robots meta:

    add_filter( 'rank_math/frontend/robots', function( $robots ) { $widget_ids_to_exclude = array('woocommerce_product_categories'); $current_widget_id = get_query_var('widget'); if (in_array($current_widget_id, $widget_ids_to_exclude)) { $robots['index'] = 'noindex'; $robots['follow'] = 'nofollow'; } return $robots; });
    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter virtual03

    (@virtual03)

    Hello @rankmathsupport),

    thank you very much for the great support!

    I have already inserted the code, but how can I check or see if it really works?

    best regards
    Daniel

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello,

    You can view the page source and locate “robots” section or you can use various online tools to see if the page is set to noindex or not.

    Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.

    Thread Starter virtual03

    (@virtual03)

    Hello @rankmathsupport,

    thank you for the hint.

    I have checked the source and cannot see that the widget is set to no index.

    you can only see that the page is indexed.
    here is a link with an example category where the code is active.

    https://www.tantra-yoga-art.de/wandbehaenge/

    https://ibb.co/25Gbq4Y

    best regards
    Daniel

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @virtual03,

    Please share more details about the page. Is it a product category or some taxonomy? You will also have to modify the filter to include the IDs in the $widget_ids_to_exclude array to set those IDs to Noindex.

    Looking forward to helping you.

    Thread Starter virtual03

    (@virtual03)

    Hello @rankmathsupport,

    exactly, it’s about the product category page and shop page.

    best regards
    Daniel

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘set widget to no index’ is closed to new replies.