// 图片alt强制标题 function image_alt($c) { global $post; // 全局量 $title = $post->post_title; // 文章标题 $s = array('/src="(.+?.(jpg|jepg|png|gif|bmp))"/i' => 'src="$1" alt="'.$title.'"'); foreach($s as $p => $r){ $c = preg_replace($p,$r,$c); } return $c; } add_filter( 'the_content', 'image_alt' );
代码来自:http://meiri.me/9047.html