I have a CSS class called .hide_elements that hides the menu, some header elements, and the footer if the class is applied to the body.

I want to provide the user with an interface. If I have to code it, or if its in a module that already exists, I’m looking for an idea of how to implement this.

Now, I can easily add this with code with hook_preprocess_html, but I need to provide a site admin the way to specify which URLs get the .hide_elements class added to it.

CSS Injector won't cut it, FYI.

Any thoughts?

closed as too broad by kiamlaluno Jun 6 at 9:13

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • You say, "I want to provide the user with an interface" - Where would that be? On a node edit form? Elsewhere? – Danny Englander Nov 8 '16 at 22:24
  • Anywhere the user can edit it (the user doesn't have access to the code) – rumblestrut Nov 9 '16 at 14:33

There are many Drupal modules to add classes to body element through interface.

1) Node Class

Node Class is a simple module that allows users to add custom CSS classes to any node through the node/add interface.

2) Body class

Add contextual CSS classes to the body of the page.

3) Extra body Class

Extra body classes is a simple module which will provide extra classes on the tag.

If you not comfortable with any of that, you can create a custom drupal form and save the classes using settings form. In preprocess_html, get the settings variable and replace in $classes variable.


Welp, turns out this was stupid simple to do using Context.

  1. Go to structure/contenxt and add a new context
  2. Add a condition of "path" and the path(s) you want the context to apply on
  3. Add a Theme HTML reaction, and give the class name you want to apply to the paths listed above.
  4. Save and enable.

Very slick.

  • 1
    Please add more details to your answer about how to do so. That may help to no longer have it show up in the "Low Quality Posts" review queue ... (which puts your answer at risk of being deleted via moderation ...) – Pierre.Vriens Nov 9 '16 at 18:18
  • Much better !!! PS: note that you'll also be able to upvote posts now ... try it! – Pierre.Vriens Nov 17 '16 at 21:26

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