Whenever I’m talking WordPress to someone, I have a habit of using terminology that is specific to WordPress. Problem is, not everyone is familiar with said terminology, and sometimes I need that reminder. At the same time, I want those that I work with, to become comfortable with the WordPress “lingo” being used as it probably won’t be the last time they’ll encounter it. That is my inspiration for this newest quick tip. We’ll be diving into one of these words that I say often – the “archive”. What is a WordPress archive? How can we, as developers, benefit from it?
If you’re learning how WordPress templates work, there are two kinds of functions you’ll see a lot. What I like to call, the “get” and “the” template functions. If you haven’t noticed by now, there are functions in WordPress that seemingly do the same thing, so what is the difference? When do you use either one? Here are some examples:
|“Get” function||“The” function|
I learned PHP through WordPress first, before I went on to solidify my PHP knowledge outside of it. If you’re in the same boat that I was, even if you’re not a beginner in other languages like HTML and Css, here is how I learned these functions.
Let’s talk about WordPress body classes! But first, an explanation of what this is. This is the first short post, from what I hope will end up being several short posts, called “Quick Tips”. It can take me weeks to write a “normal” sized post on RachieVee, and so, in an effort to keep myself active in 2019, and still pass on tidbits of knowledge, I’ve started this new category. I have also categorized these “Quick Tip” posts based on developer experience. This first post is geared towards “Beginners”. This level is meant for developers just getting to know how WordPress themes work.
What are WordPress body classes?
Back on topic! WordPress body classes are exactly what they sound like. They are HTML classes applied to the
body tag of a WordPress site. WordPress themes use the
body_class() function to apply these classes auto-magically.
If you’ve ever had an error show up on the front-end of your site, or if you’re looking to change something in a WordPress theme – taking a glance at these classes are a quick way to orient yourself. While these classes won’t tell you exactly what template to look for in a WordPress theme (unless it’s a custom page template), they can provide a clue about where you are in the WordPress template hierarchy.
Not sure what the WordPress template hierarchy is? I’ve linked to it above. It’s a flowchart of how WordPress decides what template file to display on the front-end, based on the type of content. It also differs depending on the theme.
There are only three required files for a WordPress theme: functions.php, style.css and index.php. Any other file aside from these required three, are for additional functionality and/or styling in a theme. The more template files that exist in a WordPress theme, the harder it can be to narrow down bugs or alter anything for those is still getting comfortable in said themes. Here is where the body classes can help.