Skip to content

Instantly share code, notes, and snippets.

@leavlzi
Created August 1, 2013 10:05
Show Gist options
  • Save leavlzi/6130090 to your computer and use it in GitHub Desktop.
Save leavlzi/6130090 to your computer and use it in GitHub Desktop.
// WordPress 为图片自动添加属性
add_filter('the_content', 'pirobox_gall_replace');
function pirobox_gall_replace ($content)
{
global $post;
$pattern = "/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)>/i";
$replacement = '<img$1src=$2$3.$4$5 class="img-responsive"$6>$7>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment