0

I am building a multilingual site with Polylang, and need to add custom class to my menus that groups together Pages about the same content.

For example, I have a Page "Happy" and it has a translated Page "Gelukkig" in Dutch. Polylang allows me to have different versions of the menu for each language, but I need that a common class is added to the link to the "Happy" / "Gelukkig" / ... menu element. (I will use that class to add an image before the text.)

Looking at the docs I find

.menu-item-object-category
This class is added to menu items that correspond to a category.
.menu-item-object-tag
This class is added to menu items that correspond to a tag.

But categories and tags are only available for Posts as far as I understand.

0

What you could do is add a custom field to the page, let say we name it "custom_class". Then you echo it to HTML class.

class="menu-item <?=get_post_meta( get_the_ID(), 'custom_class', true );?>"

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.