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, so that your website will be 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:

How to display a prompt box when copying text? – WordPress Tutorial

Appreciate TA
A total of {{data. count}} people
People have appreciated
⚠️
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.
Shopping Cart
Coupon
search