Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #480118

    Hello,
    My site consists of (for now):
    a) 20-30 pages in Italian (not translator program; they’re only available in Italian) but this will rise to maybe 100 or so within a few months.
    b) 6-10 pages in both Italian and English (both are required on the same page) but this will rise to 50-80 pages quickly.
    c) 3-4 pages which are exclusively in English and will stay so.

    I don’t need or want a translation plugin (aside from not needing one, I’ve seen on other sites how they slow things down).

    The problem is that if I check page source, the head lang attributes show English as the language on every single page and in the vast majority of cases these are incorrect. I tried looking on google but found loads of contradictory opinions and nothing in any case that told me how to add multiple language values to wordpress themes. My understanding is that the Lang attribute doesn’t allow showing more than one language, and so it needs to be added in the http header. How do I do this? I don’t even know where the (apparently default) En lang attribute came from.

    Thanks

    • This topic was modified 9 years, 3 months ago by brian7454.
    #480621

    Hey brian7454!

    Thank you for using Enfold.

    There is an available filter for the language_attributes function: https://developer.wordpress.org/reference/functions/language_attributes/

    Maybe, you can create a new filter in the functions.php file. Something like this:

    add_filter('language_attributes', 'language_attributes_mod', 10, 1);
    function language_attributes_mod($output) {
    	// Changes here..
    	 return $output;
    }

    Regards,
    Ismael

    #481223

    Thanks for that. I haven’t been able to find out how to use it though and I’ve no idea how to edit the code. In any event, does that set a site-wide language or allow page by page changes? The link you showed (thanks) doesn’t give any understandable guidance.

    I found this article (https://thomas.vanhoutte.be/miniblog/language-per-blogpost-wp/) which looks like it might contain an effective solution, quite simple too. However, as the majority of my pages and posts are in Italian, (or at least the most important for seo) I guess that Italian should be my default language (in terms of what gets added to page/post header attributes, not in admin) and I can then use the solution referred to above for the minority English pages.

    How do I do that? I looked at header.php and can see where it sets the language but it just says <?php language_attributes(); ?>
    That suggests it takes the language data from somewhere else (I’m no php genius). Or am I missing the point?

    Given that there are lots of websites I come across that display more than one language on a page, or have different sections in different languages (not translated) I’m surprised I can’t find much information on how to do it. I know it’s child’s play in html but if there’s a guide to doing it in wordpress it must be on page 2,527,201 of Google’s wordpress search results and I’d need to be born again several times to find something helpful!

    #482093

    Hi!

    If you want to set “Italian” as the default language, you have to add this in the wp-config.php file:

    define ('WPLANG', 'it_IT');
    

    You can then use the language_attributes filter plus the is_page conditional function to change the lang attribute on the english pages. Add something like this in the functions.php file:

    add_filter('language_attributes', 'language_attributes_mod', 10, 1);
    function language_attributes_mod($output) {
    	 if(is_page(array( 2, 55, 'Test Page' ))) {
    	 	$output = 'lang="en_US"';
    	 }
    	 return $output;
    }

    The 2 and 55 value is the id of the pages that requires modification. You can also use the actual title or slug of the page.

    Cheers!
    Ismael

    #487887

    Thank you

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Language meta tags’ is closed to new replies.