Skip to content
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

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

Open
christophdb opened this issue Sep 24, 2024 · 2 comments
Open

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

christophdb opened this issue Sep 24, 2024 · 2 comments
Labels
Enhancement New enhancement or feature request. Needs Developer An issue looking for a developer to write a PR.

Comments

@christophdb
Copy link

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:

  • language "is" "en"
  • language "is not" "en"
  • language "is any of" "en de fr"
  • language "is not any of" en de fr"

Thank you very much.

@christophdb
Copy link
Author

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?

@ndiego ndiego added the Enhancement New enhancement or feature request. label Nov 8, 2024
@ndiego
Copy link
Owner

ndiego commented Nov 8, 2024

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

I think that's a perfectly reasonable approach and is actually more performant. The blocks that do not belong to the specific language are no longer rendered. With the CSS approach, all blocks are still rendered, just hidden with styles.

@ndiego ndiego added the Needs Developer An issue looking for a developer to write a PR. label Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New enhancement or feature request. Needs Developer An issue looking for a developer to write a PR.
Projects
None yet
Development

No branches or pull requests

2 participants