I want to make a responsive theme with Bootstrap 3. However, I need to automatically add the CSS class .img-responsive
to every post image because I need the images to be responsive.
Please suggest me what I need to add in WordPress's functions.php
file or any other file that will allow me to add the CSS class automatically.
When you display post in your loop, you could do :
See https://codex.wordpress.org/Function_Reference/the_post_thumbnail for more details.
You can use jquery code on the header.php file of your theme.
since you need to have it for all of your post images, then you need to add a hook for the content and add
now add the hook to the content
However, if you already have classes for the img and you need to add a new class then you can refer to PHP equivalent to jQuery addClass. Or, you can simply do this:
The code above works .. i use it to remove src and data-src for image lazy loading. Hope it works for you
Not quite sure how good this answer is performance wise but it works. Just put this in functions.php.
Please note that you need the space after
class="img-responsive
so it doesn't merge with other classes.