Hello,
Thank you for contacting Rank Math and bringing your concern to our attention.
To modify the inLanguage property value, please add the following filter code to your site:
add_filter( 'rank_math/schema/language', function() {
return 'en';
} );
And here’s a link to how to apply this to your site:
https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php
I hope that helps.
Thank you.
Hi,
Thanks for back to us.
Can you please let me know where I have to add that code?
Thank you
Hello,
The filter should be added to your active theme’s functions.php file (last line).
Here’s another way to apply the filter using the rankmath.php file:
https://rankmath.com/kb/filters-hooks-api-developer/#adding-filters-and-hooks-in-rank-math-php
Let us know how this goes.
Thank you.
Thanks for the solution.
Ahh, one more thing if you can solve..
My website homepage content is in Hindi language and the rest pages & posts are in the English language. So, I want to change inLanguage for the header and schema markup for homepage and the rest posts.
Means is there a way to set inLanguage for a particular post & homepage?
Hope you can solve this.
Thank you
Hello,
You can replace the filter provided by my colleague with the one given below to set a separate inLanguage for your homepage and your posts:
add_filter( 'rank_math/schema/language', function() {
if (is_front_page()) {
return 'hi';
}
return 'en';
} );
Hope this helps. Let us know if you need any other assistance.
Hi,
Many thanks for your great solution, but it only works for schema markup, I want to change for header section too before <head> tag for the homepage & particular posts.
Is it possible?
Thank you
Hello,
Along with the previous code, please also add the below one to the website and see if it gives you the desired output:
add_filter('locale', function($locale) {
$posts_id = [2043, 2041]; // Add post IDs
if( is_front_page() or false != in_array(get_the_ID(), $posts_id) ){
return 'hi';
}
return $locale;
});
Here, in the $posts_id array, you’ll need to add the IDs of the posts (separated by a comma) that you wish to add the hi locale.
Here’s how you can find the ID: https://pagely.com/blog/find-post-id-wordpress/
Hope this helps.
Thank you.
Hi,
Many thanks for your all great solution. 🙂
Hello,
We are super happy that this resolved your issue. 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.