A way or rule to index terms only when they have X amount of articles?

#460296
  • Resolved LCB
    Rank Math pro

    Hi!

    I have some custom taxonomies, and I would like to keep them noindex until they get some number of articles.

    For example, if I have a taxonomy called Films, where one of the films is Titanic, I want it noindex until I write 5 articles about Titanic. Then, it will automatically change noindex to index.

    Is this possible?

    Thanks.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Anas
    Rank Math business

    Hello,

    Thank you for contacting Rank Math.

    Please add the following filter to your website and see if you get the desired output:

    add_filter( 'rank_math/frontend/robots', function ( $robots ) {
    	if ( is_category() && get_queried_object()->count < 5 ) {
    		$robots['index'] = 'noindex';
    		$robots["follow"] = 'nofollow';
    	}
    
    	return $robots;
    } );

    Here is a guide you can follow to add the filter:
    https://rankmath.com/kb/wordpress-hooks-actions-filters/

    Hope that helps.

    Thank you.

    LCB
    Rank Math pro

    Hi!

    I have added the snippet but is not working. Should I add the taxonomy name somewhere in the code, or should it work like this?

    Nigel
    Rank Math business

    Hello,

    Sorry for the mistake. We gave you an is_category condition instead of is_tax. Please replace the previous code snippet with the one below. You may need to replace ‘films’ with the correct taxonomy for your website:

    
    add_filter( 'rank_math/frontend/robots', function ( $robots ) {
    	if ( is_tax('films') && get_queried_object()->count < 5 ) {
    		$robots['index'] = 'noindex';
    		$robots["follow"] = 'nofollow';
    	}
    
    	return $robots;
    } );
    

    Hope that helps. Please let us know if you have questions.

    LCB
    Rank Math pro

    Hi!

    Yeah, now is working, thanks.

    But now… There is a way to avoid the noindex taxonomies to appear in sitemap? I want in sitemap only those who are index.

    Thanks.

    Hello,

    In this case, you may refer to this filter guide to exclude those specific taxonomies: https://rankmath.com/kb/filters-hooks-api-developer/#filter-sitemap-item

    Hope that helps.

    Thank you.

    LCB
    Rank Math pro

    I cannot make it work…

    Isn’t there a way to prevent URLs with noindex tag from appearing in the sitemap?

    Hello,

    Since you are manually setting noindex to your taxonomy pages, Rank Math won’t be able to exclude it in the sitemap.

    In this case, you would need to apply the same logic you did with the filter 'rank_math/frontend/robots' to 'rank_math/sitemap/entry'.

    Looking forward to helping you.

    LCB
    Rank Math pro

    Hi,

    what I don’t understand is… If I put this code exactly it should work? Or do I have to change something?

    `/**
    * Filter URL entry before it gets added to the sitemap.
    *
    * @param array $url Array of URL parts.
    * @param string $type URL type. Can be user, post or term.
    * @param object $object Data object for the URL.
    */
    add_filter( ‘rank_math/sitemap/entry’, function( $url, $type, $object ){
    return $url;
    }, 10, 3 );

    Hello,

    The filter code we provided in our KB articles is a placeholder so you still need to modify them to achieve the desired result.

    With that said, please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section so we can test this on your setup.

    Please do take a complete backup of your website before sharing the information with us.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    We really look forward to helping you.

    LCB
    Rank Math pro

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Hello,

    I was able to add the code to exclude the custom taxonomy that has below 5 posts inside. Please clear your website cache and check on your end if its correct.

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

    Thank you.

    LCB
    Rank Math pro

    Hi,

    Yes, seems all is working fine.

    Thank you very much for the help!!

    Anas
    Rank Math business

    Hello,

    We are super happy that your issue is resolved. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘A way or rule to index terms only when they have X amount of articles?’ is closed to new replies.