Add Custom Body Class in WordPress

Add custom body class to specific templates.

See – https://www.billerickson.net/wordpress-class-body-tag/

<?php
/**
 * Portfolio Archive Body Class
 * @author Bill Erickson
 * @link http://www.billerickson.net/wordpress-class-body-tag/
 * 
 * @param array $classes, existing body classes
 * @return array $classes
 */
function be_portfolio_archive_body_class( $classes ) {
  
  $classes[] = 'portfolio-archive';
  return $classes;
}
add_filter( 'body_class', 'be_portfolio_archive_body_class' );

About Matt Whiteley

Matt has been building bespoke WordPress websites for over 10 years specializing in the Genesis Framework. He integrates Advanced Custom Fields heavily in all builds, especially with the new Gutenberg Block Editor, allowing clients to easily modify all aspects of the their website with ease.

He works with a wide variety of small businesses and agencies across the country providing development services as well as hosting and maintenance. When he isn't coding he enjoys spending time with his wife and two children, golfing and playing poker.