图片img标签中插入alt标签

昨天罗伊来问我,如何在img标签中插入alt="文章标题",方法如下:

function photo_alt($c) {
	global $post;//全局量
	$title = $post->post_title;//文章标题
	$s = array('/src="(.+?.(jpg|bmp|png|jepg|gif))"/i' => 'src="$1" alt="'.$title.'"');
	foreach($s as $p => $r){
		$c = preg_replace($p,$r,$c);
    }
    return $c;
}
add_filter( 'the_content', 'photo_alt' );

留下评论

鄂ICP备13000209号-1

鄂公网安备 42050602000277号