ndiego / block-visibility

Conditional visibility controls for all WordPress blocks.
https://www.blockvisibilitywp.com
GNU General Public License v2.0
122 stars 10 forks source link

Hide Block based on user-language / browser-language #114

Open christophdb opened 4 days ago

christophdb commented 4 days ago

Hey there,

What problem does this address?

On our WordPress site, we offer language specific content like use-cases that are relevant for france, germany etc... French guys don't know Germany companies and other way round...

Currently we simply assign a class like "fr-only" to a block and we added this custom css code:

.fr-only {
  display: none;
}

.fr-only:lang(fr) {
  display: inline;
}

What is the problem with this approach:

This css solution is working ok, but this leads to the situation that the block is still rendered and then in the source code. It is just not shown...

I would love to see block-visibility support browser language detection because this would prevent that the content is rendered...

image

Feature request in short

It would be awesome, if you could select a language selection like:

Thank you very much.

christophdb commented 2 days ago

Just for information. We have found a workaround (probably a hack) by using cookies. We added this line of code to the functions.php to read the language of the browser with PHP and write it to a cookie. As far as we can tell, this cookie is not stored at the browser of the user, it is only available to the server and immediately readable by the plugin.

$_COOKIE['BROWSER_LANG'] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);

Then we can use the "cookie" with HideBlock. Do you have any concerns against this approach?