IMGタグのカスタマイズ

元は/wp-includes/meda.php
これの get_image_tag をfunctions.phpでカスタマイズする
元のコード

function get_image_tag($id, $alt, $title, $align, $size='medium') {

	list( $img_src, $width, $height ) = image_downsize($id, $size);
	$hwstring = image_hwstring($width, $height);

	$class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
	$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);

	$html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title).'" '.$hwstring.'class="'.$class.'" />';

	$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );

	return $html;
}

functions.phpに追記するコード

function my_remove_img_attr($html, $id, $alt, $title, $align, $size){ 

	$html = preg_replace('/ width="\d+"/', '', $html); 
	$html = preg_replace('/ height="\d+"/', '', $html); 
	$html = preg_replace('/ class=".+"/', '', $html); 
	$html = preg_replace('/ title=".+"/', '', $html); 

	return $html; 
} 

add_action( 'get_image_tag', 'my_remove_img_attr', 1 ,6);

これで、widthとheightとclassとtitleが除去される。