Archived topic
Appending custom classes to existing ones in a body section
7 replies · Started by Dalibor on August 1, 2022
I'm sure filters are the way to do it, but I'm doing something wrong.
add_filter( 'body.wp-show-posts-image', function( $classes ) {
return array_merge( $classes, array( 'floating-image' ) );
} );
The goal is to append .floating-image class to the existing .wp-show-posts-image class (a part of the WP show post plugin from Tom) located in a body of a blog page.
If it's page specific, even better.
Thanks in advance.
Hi there,
when can i see the WP Show Posts list you want to change ?
<div class="wp-show-posts-image wpsp-image-center ">
I'd like to add another class here.
<div class="wp-show-posts-image wpsp-image-center ">
This doesn't look like the body element, can you link us to where we can see the WPSP list?
Well, it is the body element.
https://prnt.sc/H-3dT2C9QtTs
I've appended the link to the page.
1. Your filter isn't correct. You can't change the filter name. For more info:
https://docs.generatepress.com/article/add-a-custom-class-to-the-body-element/
2. It's not a body element, it's just located inside the body element, like most elements on your site. So the filter won't work.
3. We have stopped supporting or updating WP show posts as the replacement of WP show posts has been released. I would recommend trying GenerateBlock's Query loop block and image block so that you can add custom classes to the GB image block.
Thank you very much.
You are welcome :)