DedeCMS织梦

织梦DedeCMS为文章图片自动添加ALT标签

阿里云

DedeCMS 在做图片站,一般都是采集,很多图片没有 alt 标签,对搜索引擎来说并不友好,一张一张写相当麻烦,可以修改为文档关键字或文章标题作为图片 alt 描述。图片的匹配度当然没有手动的好,但做站群的时候能省事就好。修改文件 include/arc.archives.class.php 找到:

  1. //设置全局环境变量
  2. $this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];
  3. SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['aid'],$this->Fields['title'],'archives');
也想出现在这里?联系我们
创客主机

在下面增加代码

  1. //替换图片Alt为文档关键字+标题
  2. $this->Fields['body'] = str_ireplace(array('alt=""','alt=\'\''),'',$this->Fields['body']);
  3. $this->Fields['body'] = preg_replace("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{0,}[\"'\s] @isU"," ",$this->Fields['body']);
  4. $this->Fields['body'] = str_ireplace("<img " ,"<img alt='".$this->Fields['keywords']." . ".$this->Fields['title']."' ",$this->Fields['body']);
  5. //end

重新生成文章即可,如果是其它字段,可以修改$this->Fields['body'] 为其它的字段名。

织梦 DedeCMS 为文章图片自动添加 ALT 标签

已有 359 人购买
查看演示升级 VIP立刻购买

收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!