New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add body class filter #101
Conversation
Hi, If you want to style your content based on the language, why not use lang attribute of html element? Instead of |
|
All true, but not really arguments for adding duplicate information to page body. Someone skilled enough to discover that there is a body class with page language can certainly add a simple filter to functions.php, if he finds out there is no such class: add_filter('body_class', function (array $classes) {
$classes[] = str_replace('_', '-', get_locale());
return $classes;
}); Also, having this filter in Polylang means that as soon as you stop using it, you lose the extra class and any rules in your CSS tied to it stop working. Whereas the snippet above or the |
Thank you for your opinion, but aren't you slightly overthinking this? It's just some body classes. There won't be any noticeable performance impact because of this change. Also, something does not have to be "new" to be useful. And fwiw, if you switch from Polylang to another multilingual plugin, I'm pretty sure you'll have some other, more severe headaches to deal with than changing a few CSS selectors in your stylesheet. I'm definitely "skilled enough", but still I'd like to see this functionality out of the box. Laziness, it's a good thing. |
No, I prefer (and encourage) generic solutions to problems, so there's less for me to remember (and for others too). Laziness is a good thing, as you say. Anyway, I said what I had on my mind and ultimately it's up to @Chouby to decide. |
I tend to agree with @chesio. There are least 2 other ways to use language specific styles without Polylang dependency which, in my opinion are better to use than an extra class.
|
No sweat, wrapped it in a plugin: https://github.com/diggy/polylang-body-class |
Note: I prefer lowercase, dashed body classes (e.g.
pll-nl-be
), so did not usesanitize_html_class()
(which would result in e.g.pll-nl_BE
)