只需在函数中添加以下代码。主题的php文件,当您将其插入post editor时,该文件会将自定义添加的类添加到图像中。
function add_image_class($html, $id, $caption, $title, $align, $url, $size, $alt = \'\' ){
$classes = get_post_meta( $id, \'classes\', true );
if ( preg_match(\'/<img.*? class=".*?">/\', $html) ) {
$html = preg_replace(\'/(<img.*? class=".*?)(".*?>)/\', \'$1 \' . $classes . \'$2\', $html);
} else {
$html = preg_replace(\'/(<img.*?)>/\', \'$1 class="\' . $classes . \'" >\', $html);
}
return $html;
}
add_filter(\'image_send_to_editor\',\'add_image_class\',10,8);