DedeCMS织梦为文章图片手动添加ALT标签
优采云 发布时间: 2020-08-13 08:21用DedeCMS在做图片站,一般都是采集,很多图片没有alt标签,对搜索引擎来说并不友好,一张一张写相当麻烦,可以更改为文档关键字或文章标题作为图片alt描述。图片的匹配度其实没有自动的好,但做站群的时侯能省事就好。百度霸屏
修改文件include/arc.archives.class.php
找到:
//设置全局环境变量
$this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['aid'],$this->Fields['title'],'archives');
在下边降低代码
//替换图片Alt为文档关键字+标题
$this->Fields['body'] = str_ireplace(array('','alt=\'\''),'',$this->Fields['body']);
$this->Fields['body'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$this->Fields['body']);
$this->Fields['body'] = str_ireplace("Fields['keywords']." . ".$this->Fields['title']."' ",$this->Fields['body']);
//end
重新生成文章即可,如果是其它数组,可以更改$this->Fields['body'] 为其它的数组名。农业经