WordPress内容页图片智能添加alt属性(自动添加文章标题作为图片alt属性)

前端之家收集整理的这篇文章主要介绍了WordPress内容页图片智能添加alt属性(自动添加文章标题作为图片alt属性)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

图片的alt属性网站seo有重要的作用,我们在使用wordpress建站添加文章页面时,很多时候会忘记添加图片的alt信息。对于有很多图片的网站,每张图片都要再去设置alt,也是一件很繁琐的事情。今天我们讲解一下给wordpress博客内容图片自动添加图片的alt属性方法

实现的原理:判断上传图片是否添加了alt属性,如果没有,会自动添加文章标题作为图片alt属性,以此来达到自动设置图片alt属性功能

切换到主题目录,打开functions.PHP文件添加如下代码

Crayon-5c891d4c78fbc839900918" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">