WordPress details optimization to automatically add ALT and title information to the article image

Friends who know a little bit about SEO optimization should understand that image ALT and image title optimization are very important SEO optimization

When we use the WordPress program to make a website, if the number of pictures on the website is large, it is necessary to optimize the picture ALT and picture title. If we manually add alt attribute and picture title attribute to each picture, it will be very troublesome, especially when there are many pictures.

Some people say that there are WordPress plugins that can automatically add ALT and title to images. There are many such WordPress plugins, but with the attitude of not using plugins, let’s share with you a little WordPress optimization tips that can automatically add ALT and title information to images of articles without plugins

//Auto add to article imagealtandtitleinformation
add_filter('the_content', 'imagesalt');
function imagesalt($content) {
       global $post;
       $pattern ="/<a(.*?)href=('|")(.*?).(bmp|gif|jpeg|jpg|png)('|")(.*?)>/i";
       $replacement = '<a$1href=$2$3.$4$5 alt="'.$post->post_title.'" title="'.$post->post_title.'"$6>';
       $content = preg_replace($pattern, $replacement, $content);
       return $content;

How to use it

It’s easy to copy the above code to the topic’s functions.php File, and then refresh the website to see the properties of the image. Are there extra ALT and tile properties?

Related Article
how to automatically add tag links to the article

Today, I'd like to share a WordPress SEO optimization tip, which can realize the automatic addition of keyword tags in Read more

WordPress displays the registration time of the login user in the frontend

When using WordPress to build a website, some users want to display the user registration time in the frontend, but Read more

WordPress adds the number of SQL queries at the bottom

An excellent woodpress theme is definitely that the less SQL consulting is used, the better. How can we see how Read more

Some WordPress articles can be seen after comments / replies

If we want to hide part of the content of the article and need the user's comments and replies to Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image