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.
I think the easiest way is to use CSS like this.
Where .content is the area that contains your post content.
Note: You may also want to override the .wp-caption class as well like so.
This approach is better: https://wordpress.stackexchange.com/questions/108831/add-css-class-to-every-image
Only caveat is that it adds the class within the edit pane when you insert new images and doesn't affect pre existing ones.
I had the same question, and adding this function to functions.php worked for me.
Classes are not added on upload, but when the image is sent to the editor. You can use the
image_send_to_editor
filter to add one or more classes. This example adds afancybox
class.You could just make all images responsive in the css as mentioned here:
I want to apply css class(bootstrap) .img-responsive on all content images
That uses LESS, but the Sass version is pretty much the same:
I think you don't require to add class to make image responsive. just remove height width from featured image, image will become responsive definitely.
There is code put in your function.php to remove height width