Wordpress - How to add CSS class to custom logo?
WordPress provide a filter hook to custom logo customization. The hook get_custom_logo
is the filter. To change logo class, this code may help you.
add_filter( 'get_custom_logo', 'change_logo_class' );
function change_logo_class( $html ) {
$html = str_replace( 'custom-logo', 'your-custom-class', $html );
$html = str_replace( 'custom-logo-link', 'your-custom-class', $html );
return $html;
}
Reference: How to change wordpress custom logo and logo link class
Here's one suggestion how we might try to add classes through the wp_get_attachment_image_attributes
filter (untested):
add_filter( 'wp_get_attachment_image_attributes', function( $attr )
{
if( isset( $attr['class'] ) && 'custom-logo' === $attr['class'] )
$attr['class'] = 'custom-logo foo-bar foo bar';
return $attr;
} );
where you adjust the classes to your needs.
As you found yourself the_custom_logo
relies on get_custom_logo
, which itself calls wp_get_attachment_image
to add the custom-logo
class. The latter function has a filter, wp_get_attachment_image_attributes
which you can use to manipulate the image attributes.
So what you could do is build a filter that checks if the custom-logo
class is there and if yes add more classes.