This time's WordPress tutorial will teach you how to simply add alt tags to images automatically, making your website more popular with spiders
In fact, the image alt tag in the article is used to describe what the image is about. It can not only show to your visitors, but also better attract search engine spiders. It is beneficial and harmless, but it needs to be manually added one by one. It is a bit troublesome. So, is there a simple way?This timeWordpress TutorialTeach you how to simply add alt tags to pictures automatically.
Add the following code to thefunctions.phpIn file<?phpNow, just save it.
/**Automatically add Alt tags to pictures*/function image_alt_tag($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').'"', $images[0][$index]);$content = str_replace($images[0][$index], $new_img, $content);}}return $content;}add_filter('the_content', 'image_alt_tag', 99999);
When you add the above code, it will automatically give youAll pictures of the websiteAdd aCombined by current article name and website nameThe alt tag of, of course, will not affect your normal addition of "alternative text" to the image.
If you rarely add "alternative text" to the image manually, this code is suitable.
Some codes and tutorials on Npcink come from the Internet, and are only for netizens to learn and exchange. If you like this article, you canAttach original linkReprint at will. No intention of infringing your rights, please send an email to1355471563#qq.comOr click on the rightPrivate message: Muze feedback, we will deal with it as soon as possible.