希望这能起到作用:
/**
* Append the image categories to the current image class.
*
* @see http://wordpress.stackexchange.com/a/156576/26350
*/
add_filter( \'get_image_tag_class\',
function( $class, $id, $align, $size )
{
foreach( (array) get_the_category( $id ) as $cat )
{
$class .= \' category-\' . $cat->slug;
}
return $class;
}
, 10, 4 );
测试(WP 3.9.1):如果我们将图像类别设置为(例如):
rolling-stones, steel-wheels-tour, wembley
屏幕截图:

然后将图像插入帖子,我们得到了预期的额外类:
category-rolling-stones category-steel-wheels-tour category-wembley
屏幕截图:
