Last active
April 16, 2018 17:21
-
-
Save CoachBirgit/e2c79015dae3026d7b56 to your computer and use it in GitHub Desktop.
WordPress: Add 'img-responsive' class via filter to 'the_content'
This file contains hidden or 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
// add default class for img-responsive | |
function add_image_responsive_class($content) { | |
global $post; | |
$pattern ="/<img(.*?)class=\"(.*?)\"(.*?)>/i"; | |
$replacement = '<img$1class="$2 img-responsive"$3>'; | |
$content = preg_replace($pattern, $replacement, $content); | |
return $content; | |
} | |
add_filter('the_content', 'add_image_responsive_class'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
don't need the global $post