Another way that I was solving <body>
and other formatting for templates is to create a CSS file specific for the template and then insert it dynamically into the <head>
from the template. In functions.php
of your theme, add a function to spit out a <link>
to the CSS:
function mytemplate_head () {
echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('template_directory').'/mytemplate.css" />'
}
Then in the top of your template file before get_header();
, add this line of code:
add_action ( 'wp_head', 'mytemplate_head' );
Since the mytemplate.css
file will be loaded after your theme CSS, you can over-ride your theme CSS for <body>
if you use !important
flag after your property declarations:
body {
background: #000 !important;
}
https://codex.www.ads-software.com/Function_Reference/add_action
https://www.w3.org/TR/CSS2/cascade.html#important-rules