0

Question 1

I'd like to be able to show or hide certain pages in the main navigation menu based on whether or not they have certain prefixes in their title. This is mostly for the purpose of language translation. Example:

If /url?ln=spanish then I want the navigation bar to only show pages that were prefixed with spanish. But my problem is I don't know how to manipulate the correct variables or data structures. While googling I've been playing around with wp_get_nav_menu_items but I'm not sure. What file should my logic reside in and what data structure holds the menu items?

Question 2

Is it possible to do the same thing on the main page index.php? Basically I'd like to hide or show certain Blog posts depending upon what prefix is in their title.

  • You're likely to get more attention by giving each question its own question so that people can answer q1 without needing to answer q2 and vice versa – Tom J Nowell Oct 27 '15 at 20:37
  • @TomJNowell True. They overlap so I wanted to avoid duplicating questions but I see your point. – Usman Mutawakil Oct 27 '15 at 21:23
2

I'm sure what you're asking can be done, but there's a far simpler, significantly easier solution, just register each menu multiple times for each language, and show different menus for different languages.

This way you don't need to figure out how to filter out menu items depending on GET variables, and your pages become more cacheable ( you could modify rewrite rules so that your URLs are pretty and take the form example.com/es/hello-world rather than example.com/hello-world?lang=es )

The benefit of this is that your language menus can be completely different, and they'll work everywhere on your site, not just on posts and pages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.