Add class "has-post-thumbnail" to body element

Hi,

since there is no conditional logic built in, it would be nice to know, if the post or page has a featured image to show or hide elements at least via css, which would make a lot things easier (eg a post header with the featured image in the background).

This would also grant the possibility to have different post layouts for posts with or without featured images.

I know i can use a child theme and simply add a function that adds the class, but most of the time a child theme isn´t necessary.

Another option would be a “has post thumbnail” condition in the template conditions, so you can create two “post-header” templates conditionally.

Let me know what you think.

Regards,
timmse

2 Likes

@timmse

Nice suggestion :+1:t3: It would also be great if (custom) taxonomies are added as classes in the body ánd when using the custom Query. On another site, I used this to change background colors based on the taxonomy value.

I believe WordPress does this natively on their end, so I really hope this isn’t much effort to implement.

Regards,

PB86