Modify the Featured Image CSS Classes in Genesis

Genesis has a useful filter for modifying the attributes of almost any element it outputs. For instance, the featured image on archive pages has an attribute name of ‘entry-image’, so can be modified using the filter genesis_attr_entry-image.

The code below allows you to add a custom CSS class to the featured image using this filter.

<?php
/**
* Modify the Featured Image CSS Classes
* @author Bill Erickson
* @link http://www.billerickson.net/code/genesis-featured-image-classes
*
* @param array $attr, existing attributes
* @return array $attr
*/
function be_genesis_featured_image_classes( $attr ) {
$attr['class'] .= ' custom-class';
return $attr;
}
add_filter( 'genesis_attr_entry-image', 'be_genesis_featured_image_classes' );
view raw functions.php hosted with ❤ by GitHub

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk