Skip to content

Instantly share code, notes, and snippets.

@xardit
Created June 23, 2023 21:02
Show Gist options
  • Save xardit/b498e366240020ca3df45c65a6d6865a to your computer and use it in GitHub Desktop.
Save xardit/b498e366240020ca3df45c65a6d6865a to your computer and use it in GitHub Desktop.
WP Change Language Attribute on HEAD based on specific slug
<?php
// set language attribute of the main <html> tag based on category value
function new_language_attributes($lang){
if(is_single()) {
$ar = get_the_category();
foreach($ar as $c) {
if($c->slug=='in-italiano') {
return "lang=\"it\"";
}
}
}
return $lang;
}
add_filter('language_attributes', 'new_language_attributes');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment