Skip to content

Instantly share code, notes, and snippets.

@macariojames
Last active September 1, 2019 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macariojames/ded9109b4ac323162e07af3850a15d7c to your computer and use it in GitHub Desktop.
Save macariojames/ded9109b4ac323162e07af3850a15d7c to your computer and use it in GitHub Desktop.
Add .img-responsive class to all images uploaded/added in WordPress
<?php
/**
* @desc Add .img-responsive to all post images ~mj
*/
function add_post_img_responsive_class($attr) {
$attr['class'] .= ' img-responsive'; // note the leading space
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'add_post_img_responsive_class');
/**
* @desc Add .img-responsive to all editor images
*/
function add_editor_img_responsive_class($class) {
$class .= ' img-responsive'; // note the leading space
return $class;
}
add_filter('get_image_tag_class', 'add_editor_img_responsive_class');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment