How to automatically add alt tags to images- Wordpress Tutorial

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 time Wordpress Tutorial Teach you how to simply add alt tags to pictures automatically.

 How to automatically add alt tags to images- Wordpress Tutorial
Background picture

Add the following code to the functions.php In file <? php Now, 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 you All pictures of the website Add a Combined by current article name and website name The 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.

Next Wordpress Tutorial Shared an interesting function, you can also see:

怎么自动给图片添加alt标签? - wordpress教程-Npcink
怎么自动给图片添加alt标签? - wordpress教程-Npcink

How to display a prompt box when copying text- WordPress Tutorial

course

Exquisite mouse click fireworks effect - WordPress beautification

2020-3-27 23:32:30

course

Wordpress beautification - how to add online customer service code?

2020-3-28 17:39:29

⚠️
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 can Attach original link Reprint at will.
No intention of infringing your rights, please send an email to 1355471563#qq.com Or click on the right Private message: Muze feedback, we will deal with it as soon as possible.
0 replies A Author M administrators
    There is no discussion yet. Tell me your opinion
Personal Center
Shopping Cart
Coupon
Sign in today
There are new private messages Private Message List
search