Mismatched hreflang and HTML lang declarations

[ad_1]

in the meantime, I found the solution for my case
I needed to adjust the php code
I edited the functions.php file in my theme

and added the code below:

add_filter('language_attributes', 'custom_language_attributes', 10, 2);
add_filter('pll_rel_hreflang_attributes', 'custom_hreflang_attributes');

function custom_language_attributes($output, $doctype)  function custom_hreflang_attributes($hreflang_attributes)  $modified_attributes = [];

 foreach ($hreflang_attributes as $lang => $url)  if ($lang === 'pt' 

return $modified_attributes;

This code does the following:

  1. Keeps the lang attribute of the <html> tag as “en-US” for English pages.
  2. Sets the lang attribute to “pt-br” for Portuguese pages.
  3. Modifies the hreflang attributes of the <link> tags to use “en-US” for English and “pt-br” for Portuguese.

Now everything is ok!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer