

Rather than focusing on canonical American authors who wrote at the time of U.S. Simultaneously, new technologies of vision emerged for imagining the human body, including the moving camera, stereoscopes, and more efficient print technologies for mass media. During this period, the American national territory expanded beyond its continental borders to islands in the Pacific and the Caribbean. } Adding a Body Class Based on the Page Templateīy default, WordPress adds a body class for your page template, but if you are a front-end developer and have naming conventions for your CSS, then you may want to change this.Īs an example, a page template called "halfhalf" would have a body class of page-template-page-halfhalf-php-not great.Body Parts of Empire is a study of abjection in American visual culture and popular literature from the Philippine-American War (1899–1902). Taking the same example that we used earlier, we can achieve the same effect: add_filter( 'body_class','my_body_classes' ) } Conditionally Adding a Body Class by FilterĬonditions can also be used in a filter. To add more classes to the filter, just add another line that adds another value to the array: add_filter( 'body_class','my_body_classes' ) This adds a class (or classes, depending on your implementation) to the array and returns the entire array. add_filter( 'body_class','my_body_classes' )

#The body and the archive code
This code can either go in your theme's functions.php or within your plugin. This method keeps the theme code cleaner and is particularly useful if you want to add a body class from a plugin. It's possible to use a WordPress filter to add a body class, too. If it is true, then the body class has is-woocommerce-shop added to it if it's not true, then just the default body class is displayed. What the above code is doing is checking that the first function is returning true. Note: WooCommerce already adds a class based on this, so note that this is purely an example. This example uses the WooCommerce conditional method of is_shop() : You may also want to conditionally add a body class. This takes all of the classes in the array and passes them to the body_class function. This can be achieved using a simple array: > There may be times when you want to add more than one body class. All such classes added by WordPress are mentioned in the WordPress documentation. If you were planning to add some classes to the body tag in order to target these kinds of posts and pages, it might just be better to use the classes added by default. These dynamic classes allow you to target pages and posts for very specific styling.
#The body and the archive archive
If you visit the archive page for the tutorial category, you will see that its body tag also contains classes like category-tutorial. For example, let's say your website has some posts filed under the category "tutorial" and other posts filed under "tip". The body_class() function also adds a bunch of classes that can be used to target things like archive pages of a specific tag or category. This allows you to style the contents of a page selectively, depending on its type. Similarly, other classes like category, archive, search, and tag are added automatically to the body tag if the user is viewing a specific type of page. The class logged-in will not be added to the body if a logged-out user is viewing the page.


One such example would be the logged-in class that is added to the body tag if a logged-in user is viewing the page. The body_class() function in WordPress makes this very easy for us by automatically adding a bunch of appropriate classes to the body tag of our website. Default Static and Dynamic Body Classes in WordPressĬlasses are usually added to any element to target them either for styling using CSS or for manipulating their content using JavaScript. This would add a body class of my-class on each page of your WordPress site. To add your own class to this, you can pass an argument in to the function, like so: The body class is normally included in a theme using the following code: This is a really simple way to add body classes and is especially useful if you are creating a theme. Editing the Theme: Passing a Body Class Value This tutorial is going to cover adding the body class within a theme (usually defined in header.php) using the body_class function and adding classes using a filter. There are a few methods available to us for adding new body classes within WordPress.
