I am trying to make it so that when a body image is inserted into a page, that the bootstap class "img-responsive" is added to the image tag?
Can anyone tell me how to achieve this?
I am trying to make it so that when a body image is inserted into a page, that the bootstap class "img-responsive" is added to the image tag?
Can anyone tell me how to achieve this?
You can do this through image formats:
The "Full width" / "Left-aligned" / "Right-aligned" options you usually get when inserting an image into the rich text area come from Format objects, which determine how to translate the image reference into the final tag. So, you need to replace the built-in Format objects with ones that insert your classname. Create a file 'image_formats.py' within your app, containing the following:
from wagtail.wagtailimages.formats import Format, register_image_format, unregister_image_format
unregister_image_format('fullwidth')
register_image_format(Format('fullwidth', 'Full width', 'richtext-image full-width img-responsive', 'width-800'))
unregister_image_format('left')
register_image_format(Format('left', 'Left-aligned', 'richtext-image left img-responsive', 'width-500'))
unregister_image_format('right')
register_image_format(Format('right', 'Right-aligned', 'richtext-image right img-responsive', 'width-500'))