Not Able to Remove Default Class From WP Elements and Add New Custom Classes

Question

Using WordPress 5.3.2 I am trying to remove some default classes from WP native elements and add mu custom classes to them which apparently it is not working.

As you know in adding an image to the Post/Page we are getting this HTML at front end

<div class="wp-block-image">
    <figure class="aligncenter size-large">
        <img src="https://../../image.png" alt="" class="wp-image-156">
    </figure>
</div>

Now I need to update the css classes to be like blow by removing default classes wp-block-image (from figure wrapper div), and aligncenter size-large (from the figure) and wp-image-156 from the image tag and add the figure-img img-fluid rounded to image …

<div class="wp-center-block">
    <figure class="figure">
        <img src="https://../../image.png" alt="" class="figure-img img-fluid rounded">
    </figure>
</div>

I already tried adding this function to functions.php

function add_image_class($class){
    $class .= ' figure-img img-fluid rounded';
    return $class;
}
add_filter('get_image_tag_class','add_image_class');

but this is not adding the classes to the image and also not removing the wp-image-156 from class. Can you please let me know how to fix this?

0
Behseini 4 years 2020-03-10T20:53:02-05:00 0 Answers 121 views 0

Leave an answer

Browse
Browse