0

I've just created a "full-width" template page for my theme, allowing me to set the width of the site content to maximum if there are no sidebars active.

What I've noticed is that this gave me a HTML class ".full-width" to work with in CSS. How did this class get generated? It seems to be terrifically connected with the fact that I named my template "full-width.php"

  • Yes, WordPress adds tons of classes automatically. One of them is template files name class. Read more about body_classes on codex. – Robert hue Dec 16 '14 at 9:26
  • Ah yes now I understand. I hooked into body_class in functions.php to add 'full-width' Thanks. – Rockett Dec 16 '14 at 9:38
  • @Roberthue as an answer please. :) – Rarst Dec 16 '14 at 16:31
0

By default WordPress adds lots of CSS classes in body tag automatically. These body classes are very useful for styling different sections/pages of site without needing to edit theme files unnecessarily.

For example WordPress add home CSS class on website front page and blog class on blog posts index page.

Similarly in your case, since you are using a custom page template for a page, WordPress added file name CSS class in body tag.

You can read more about body_classes in codex and a brief list of all CSS classes added by WordPress.

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.