首页>文档>其他文档>wordpress>WordPress 图片自动添加alt和title

WordPress 图片自动添加alt和title

主题目录functions.php文件中添加以下代码:

默认显示文章标题和网站标题

// /** 图片自动添加alt和title */function image_alt_title($content){    global $post;preg_match_all('/<img (.*?)\/>/', $content, $images);    if(!is_null($images)) {foreach($images[1] as $index => $value)    {        $new_img = str_replace('<img', '<img alt="'.get_the_title().'-'.get_bloginfo('name').'"'.'title="'.get_the_title().'-'.get_bloginfo('name').'"', $images[0][$index]);        $content = str_replace($images[0][$index], $new_img, $content);}}        return $content;}add_filter('the_content', 'image_alt_title', 99999);

保存文件后,刷新看下吧

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧