Last active
September 1, 2019 15:07
-
-
Save macariojames/ded9109b4ac323162e07af3850a15d7c to your computer and use it in GitHub Desktop.
Add .img-responsive class to all images uploaded/added in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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