zblog教程 | 2019年10月31日14时36分26秒 | 评论:0
alt是图片标签img的一个属性,其作用除了在图像无法显示时,浏览器把alt属性值替代图片显示外,在SEO优化中也是非常重要的一个标签属性,时下的seo检测工具都把alt列为重要检测指标。
在使用zblog php编辑器上传插入图片过程中,博主往往会忽略或者漏掉图片alt,事后想起再逐一检查显然极度消耗时间,而通过函数代码则可以自动给所有图片添加alt属性,一劳永逸。
1、编辑主题的include.PHP文件,在最后一行的?>
上面添加下面的函数代码:
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); }
2、在include.php文件的ActivePlugin_主题ID()
函数部分,添加挂载接口代码:
Add_Filter_Plugin('Filter_Plugin_ViewPost_Template','imgAlt');
3、保存后,文章中的图片就会自动添加alt属性,并把文章标题设置为alt属性值。
相关文章
网友点评
本文暂无评论 - 欢迎您
⎛⎝爱站云⎠⎞
AiZhanCloud.Com