• Resolved CB

    (@cbrandt)


    Hello,

    I have a website with content in 3 languages. I use custom functions in my theme’s functions.php to change locale for 2 of them. I also have a sitemap that maps posts to their respective hreflang tag.

    I just noticed, however, doing an advanced search on Google and using the Language field, that Google, while properly returning results for 2 of the languages, is returning posts in all 3 languages when I search for the main language.

    In the Schema markup added by Yoast, I’ve noticed there’s a field “inLanguage” that is set to the main language no matter what locale or hreflang the posts have. So I’m guessing this is what is making Google list all the posts as if from the main language.

    Is there a way to customize the output of this inLanguage field?

    Thanks a lot,
    CB

    • This topic was modified 5 years ago by CB.
    • This topic was modified 5 years ago by CB.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Sa?a

    (@stodorovic)

    I think that works in WPML. Yoast SEO should uses locale. If you are running newer WP, then you can try to use filter determine_locale.

    If you can’t override locale on previous way then you can try to use filter wpseo_schema_webpage (I think that the argument is array of pieces).

    Thread Starter CB

    (@cbrandt)

    Thanks for your suggestions.

    The locale is being properly set. The only signal that is not right is inLanguage, so that, for instance, in an English-language page I have:

    <html lang="en-US">
    <meta property="og:locale" content="en_US" />
    "inLanguage":"pt-BR"

    I’ll read more about the filter you mentioned, see if I can find a recipe somewhere that I can adapt to my needs.

    Best regards

    Thread Starter CB

    (@cbrandt)

    Thanks for pointing me in the right direction, @stodorovic.

    To change inLanguage in the Schema markup generated by Yoast SEO, the following code in my child theme’s functions.php worked for me. In my setup, I have two categories that identify posts by language:

    function change_inLanguage( $data ) { 
      if ( in_category( '49' ) ) {
    	  $data['inLanguage'] = 'en-US'; 
      }
      else if ( in_category( '52' ) ) {
    	  $data['inLanguage'] = 'es-ES'; 
      }
      else {
    	  $data['inLanguage'] = 'pt-BR'; 
      }
      return $data;   
      }
    
    add_filter( 'wpseo_schema_webpage', 'change_inLanguage' );

    Best regards

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to change inLanguage in Schema markup’ is closed to new replies.