Noindex Posts of specific Languages (TranslatePress)

#473702
  • Resolved ibirone
    Rank Math free

    Hi there!

    We are using Rankmath + Translatepress Pro on our website.

    Currently the main language is English with German and Spanish currently deployed (all pages + posts translated & indexed).

    For the future languages, we’d like only translate & index the pages and noindex posts.

    How can I use Rankmath at scale to Noindex posts for Portugese posts, French posts, etc?

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Nigel
    Rank Math business

    Hello,

    Thank you for contacting Rank Math for help with setting translated pages to ‘noindex’ on your website.

    You will have to modify the filter below to set translated pages to noindex:

    
    /**
     * Allows filtering of the robots meta data.
     *
     * @param array $robots The meta robots directives.
     */
    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	return $robots;
    });
    

    Please contact TranslatePress support for help adding the translation conditions to the code (eg if current language is ‘fr’ then …)

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

    ibirone
    Rank Math free

    Hi Nigel,

    thank you!

    We went with the following for now:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
      $url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
      if(is_single() && strpos($url, '/pt/')) {
        $robots["index"] = 'noindex';
        $robots["follow"] = 'nofollow';
      }
      return $robots;
    });

    Another questions that just came up..

    Is there an option / filter to remove exactly those posts from the sitemap?

    Hello,

    You can use a filter with the same logic for those translated posts:
    https://rankmath.com/kb/filters-hooks-api-developer/#filter-sitemap-item

    Here’s an example filter you can customize to remove them in your sitemap:

    add_filter( 'rank_math/sitemap/entry', function ( $url, $type, $object ) {
    
            $urls_to_skip = array(
                    'https://yourdomain.com/redirected-URL-1',
                    'https://yourdomain.com/redirected-URL-2',
                    'https://yourdomain.com/redirected-URL-3',
            );
    
            if ( isset( $url['loc'] ) && in_array( $url['loc'], $urls_to_skip ) ) {
                    return false;
            }
    
            return $url;
    }, 10, 3 );

    Hope that helps.

    Thank you.

    ibirone
    Rank Math free

    Hi Reinelle,

    I’m not sure how to implement that correctly (my knowledge of PHP is extremely limited)

    Would I still use

    if(is_single() && strpos($url, '/pt/'))

    to store all Portugese post urls in the array $urls_to_skip?

    How exactly would I use it with your example filter mentioned?

    Thanks for your help!

    Nigel
    Rank Math business

    Hello,

    When posts are set to noindex they should be automatically be removed from the sitemap.

    Can you please follow these steps?
    1. Flush the Sitemap cache by following this video screencast:
    https://i.rankmath.com/pipRDp
    2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
    https://rankmath.com/kb/exclude-sitemaps-from-caching/

    If flushing the sitemap cache does not work, I have adjusted the code snippet to remove sitemap entries

    
    add_filter( 'rank_math/sitemap/entry', function ( $url, $type, $object ) {
       if ( isset( $url['loc'] ) && strpos($url['loc'], '/pt/')){
          return false;
       }
       return $url;
    }, 10, 3 );
    

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

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Noindex Posts of specific Languages (TranslatePress)’ is closed to new replies.