Archived topic
html file location
7 replies · Started by Yaeko on April 22, 2022
hi!
I am creating 2 language web site. not auto translate.
made up japanese first, so I duplicate page for English, change contents of languages.
now I want to control language and type font. so I thought it is good idea for me to change html file. (as per attached) so I can add css later on. asked google where is root file. wp-contents>theme> but with generatepress, I can't find it!
so please let me know how to control this, change lang ja to en for some pages.
oops! no attach file facility! but you know what I am talking about ya! just after <!doctype html> <html lang="ja"> to en.
thank you in advanced!
Hi there,
you can use the WordPress language_attributes filter:
https://developer.wordpress.org/reference/hooks/language_attributes/
Heres an example of someone using that filter to switch languages based on the post category term:
https://www.barattalo.it/coding/modify-the-language-attributes-based-on-category-in-wordpress/
great, david. I will study and dive into it.
ciao
You're welcome
but the article mentioned function works by categories, post....
my case is all pages, not post...
cheers
Yeah... you will need 'something' to identify what language the page is in. So you could add this PHP snippet to enable Categories on your page:
add_action( 'init', function(){
register_taxonomy_for_object_type('category', 'page');
});
Then create a Category Term called english and apply it to your english pages.
Then the snippet from the barattalo website could look like this:
function new_language_attributes($lang){
if(is_singular()) {
$ar = get_the_category();
foreach($ar as $c) {
if($c->slug=='English') {
return "lang=\"EN\"";
}
}
}
return $lang;
}
add_filter('language_attributes', 'new_language_attributes');
ohhhhhhhh ok..... not sure I can handle it but great great information. you have wonderful knowledge!
so thank you!
I hope it can work for you :)
Glad to be of help