Roots Discourse

Any way to stop formatting classes for menu items?

Okay so I posted this over on WP.orgs forums and got a typical useless response from a moderator.

Noticed when I save classes in the backend for menu items it strips out some characters, like saving md:flex turns into mdflex after saving it.

Moderator claims it’s a theme related issue, if it is, how do I stop it?

Can confirm this is a wordpress core function.

I bet you could alter it with a filter hook. Here’s some starting points for your search:

Sorry, I’m not sure where the sanitization actually happens just yet.

Pretty sure this is happening in the WP Nav Walker. You can see the source here: I’m on my phone so the code is a little difficult to read, but it looks like the classes are being sanitized by esc_attr(). It looks like all the available filters in the Walker happen before the classes are sanitized, but it looks like there’s a filter on esc_attr that would allow you to filter content after it’s been sanitized, to “re-add” your correct classes:

You could also change your tailwind config to use a separator that WP won’t strip out: I’ve done this on a few projects, and it works fine.