ZBLOG自动为内容图片添加alt属性 利于SEO效果

我们在使用ZBLOG PHP程序的时候,很多朋友们反馈到默认直接上传到ZBLOG的图片没有自带ALT属性,而是图片的名称,很不友好。于是我们会采用手动的方式编辑添加图片alt。有没有一个自动模式,可以实现ZBLOG自动为内容中的图片加上alt属性呢?

// 自动ZBP图片ALT itbulu.com整理自网络
function imgAlt(&$template){
	global $zbp;
	$article = $template->GetTags('article');
	$pattern = "/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>/i";
	$replacement = '<img alt="'.$article->Title.'" src=$2$3.$4$5/>';
	$content = preg_replace($pattern, $replacement, $article->Content);
	$article->Content = $content;
	$template->SetTags('article', $article);
}

将代码添加到include.php主题这文件最后,然后再添加钩子。

Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','imgAlt');

这个一般是添加的是网站标题作为ALT,至少比没有好一些。

本文出处:老蒋部落 » ZBLOG自动为内容图片添加alt属性 利于SEO效果 | 欢迎分享( 公众号:老蒋朋友圈 )

公众号 「老蒋朋友圈」获取站长新知 / 加QQ群 【1012423279】获取商家优惠推送