替换Ecshop系统中产品描述部分的图片的alt图片描述
处于SEO图片部分优化的考虑,我们常常需要在产品描述中添加的图片有alt描述内容,但是大多数时候在添加图片的时候又没有添加图片的描述信息,
这就需要在程序的部分来考虑自动为没有添加alt信息(这是alt="")设置相关内容;
下面以修改alt=""的部分修改alt="产品名称"为例:
修改include/lib_goods.php文件,在函数get_goods_info中的
/* 修正商品图片 */
$row['goods_img'] = get_image_path($goods_id, $row['goods_img']);
$row['goods_thumb'] = get_image_path($goods_id, $row['goods_thumb'], true);
$row['goods_img'] = get_image_path($goods_id, $row['goods_img']);
$row['goods_thumb'] = get_image_path($goods_id, $row['goods_thumb'], true);
下面添加一行
$row['goods_desc'] = preg_replace('/alt=([\'|\"]){2}/','alt="'.$row['goods_name'].'"',$row['goods_desc']);
附加:替换所有图片的alt内容为指定内容代码:
preg_replace('#alt="[^"]*"#i','alt="".$title.""',$str);