织梦文章内容页图片自动适配百度MIP方法

不用修改织梦程序内核文件,不影响电脑站和手机站文章内容页的文章内容输出,增加个自定义方法来解决织梦MIP文章内容页图片适配百度MIP规范

织梦文章内容页图片自动适配百度MIP方法

操作步骤:

织梦文章内容页图片自动适配百度MIP方法

width|height 去除图片宽高

style 去除内联样式

/uploads/ 相对路径图片路径替换成绝对路径

打开 /include/extend.func.php 在最下面加入个方法:

/**
* MIP文章内容页图片适配百度MIP规范
*
* @access public
* @param string $content 文章内容
* @return string
*/
function mip($content){
global $cfg_basehost;
preg_match_all('/织梦文章内容页图片自动适配百度MIP方法/', $content, $images);
if(!is_null($images)) {
foreach($images[1] as $index => $value){
$mip_img = str_replace('织梦文章内容页图片自动适配百度MIP方法', '>', $mip_img);
$mip_img = preg_replace('/(width|height)="\d*"\s/', '', $mip_img );
$mip_img = preg_replace('/ style=\".*?\"/', '',$mip_img);
$content = str_replace($images[0][$index], $mip_img, $content);
}
}
preg_match_all('/ style=\".*?\"/', $content, $style);
if(!is_null($style)) {
foreach($style[0] as $index => $value){
$mip_style = preg_replace('/ style=\".*?\"/', '',$style[0][$index]);
$content = str_replace($style[0][$index], $mip_style, $content);
}
}
$content = str_replace('/uploads/', $cfg_basehost.'/uploads/', $content);
return $content;
}

内容页模板标签写法

{dede:field.body function=mip(@me)/}

业界动态

Dedecms织梦列表文档总数量用标签输出的方法

2018-10-24 21:44:05

业界动态

如何理解百度SEO优化的“千人千面”

2018-10-25 16:54:17

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索