您可以创建content_filter
这将即时更新,意味着你不必更新所有以前的图片,这将是默认的,因此你不必担心你的作者。类似这样:
function autoadd_rel_prettyPhoto($content) {
global $post;
$pattern = "/(<a(?![^>]*?rel=[\'\\"]prettyPhoto.*)[^>]*?href=[\'\\"][^\'\\"]+?\\.(?:bmp|gif|jpg|jpeg|png)[\'\\"][^\\>]*)>/i";
$replacement = \'$1 rel="prettyPhoto[\'.$post->ID.\']">\';
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
add_filter("the_content","autoadd_rel_prettyPhoto");