Programmatically add classes to site images

Public

Adding Bootstrap's img-responsive class to all site images.

</> CopyGet raw version
php
  1. /**
  2.  * Image Preprocesses
  3.  * Adds bootstrap class to all images
  4.  */
  5.  
  6. function yourTheme_preprocess_image(&$vars) {
  7. $vars['attributes']['class'][] = 'img-responsive';
  8.  
  9. // This test is for images that are displayed in 'original' format.
  10. // http://getbootstrap.com/css/#overview-responsive-images
  11. }
  12. function yourTheme_preprocess_image_style(&$vars) {
  13. $vars['attributes']['class'][] = 'img-responsive';
  14.  
  15. // This test is for images that have an image style or format applyed.
  16. // http://getbootstrap.com/css/#overview-responsive-images
  17. }