Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
1.6k views
in Plugins by
edited by

I like to target specific main areas (.qa-main) by their body class. Different styles on different sites, but .qa-main is persistent. That was a tip of gidgreen once.

However, problems occur when I have a plugin page. Each plugin page has the body class ".qa-template-plugin".

How can I specify a custom CSS name for the body tag?

1 Answer

+2 votes
by
selected by
 
Best answer

Call qa_set_template(...) with the name you want to use.

by
In function process_request($request) I added:
    // set CSS class in body tag
    qa_set_template('my-custom-stuff');

Nice! Thanks a lot :-)
by
Extension of the question: How can I add a custom CSS class to a "custom page". Each custom page has only ".qa-template-custom" for now.
by
I thought you would need to do this with a layer which modifies the body_tags() function.
by
I am using the "advanced theme" and override function body_tags() as you suggested. This works:

/* override to add custom CSS class in body tag */
function body_tags() {
    $class='qa-template-'.qa_html($this->template);
    if($this->request=='punkte'){
        $class='qa-template-custom-punkte';
    }
    $this->output('CLASS="'.$class.' qa-body-js-off"');
}

(!) Thanks ;)
by
Now I can get rid of all CSS styles in plugin pages and custom pages, and only use a global stylesheet. Plus another stylesheet for mobiles! ... check it out on your smartphone: http://www.gute-mathe-fragen.de/
...