Wordpress SEO - What are you looking for?

If you're looking for answers to SEO or wordpress related questions, type in a phrase and wait for hints or click enter! The results also show links to external sources.

161 articles in the database

How to automatically populate the title, label, alternative text and description fields when uploading images?

[ Article content is protected by Plagiashield ]

3

If you are running blog at WordPressThis is the time since the need arises to upload images and add them to articles. And although this process does not take too much time, but no one will be against it to reduce it. So, we will present you a simple catch to save some time under the time of adding images to WordPress. Especially since introducing it is no problem at all.

The given hook will not speed up the process of loading images. Unfortunately it quite depends on parameters hosting and you need to be careful when choosing a server for websites www. However, we can add the ability to auto-fill half title, label, alternative text and description under the time of loading images. And this simple action will save some time every time you add an image to pageswww.

If you do not fill in the fields mentioned above (Fig. 1), then you can make no changes to the code. However, you must be aware that the alt attribute plays an important role for the image. Based on its Google It "understands" to which topic the photo belongs and "attaches" the corresponding query to it. So you can get additional traffic from the "Graphics" service Google" when a visitor searches for your topic. In addition, filling in the title and alternative text fields adds weight website, co is important for its positioning.

Figure 1: Adding a picture to the library Media

We encourage you to fill in the title, label, alternative text and description fields when adding an image to your website. And the code below will allow you to do that instead of you:

function wph_auto_alt_title_caption($attachment_ID) {
$filename = $_REQUEST['name'];
$withoutExt = preg_replace('/{[^.}]{3,4}$/', '', $filename);
$withoutExt = str_replace(array('-','_'), ' ', $withoutExt);
 
$my_post = array(
'ID' => $attachment_ID,
'post_excerpt' => $withoutExt, // Label
'post_content' => $withoutExt, //description
   	 );
    	wp_update_post($my_post);
 
    	//attribute alt
   	 update_post_meta($attachment_ID, '_wp_attachment_image_alt', $withoutExt);
}
add_action('add_attachment', 'wph_auto_alt_title_caption');

This code uses the name of the image and when it loads on the page, it inserts the given name into the title, label, alternative text and description fields. In doing so can be come slightly offwhetherm automatically fill in each half by deleting the corresponding piece in the code.

Add the above code to the file functions.php theme used by default. This can be done using the standard editor. It is located in the Appearance => Editor panel administrative WordPress (Figure 2).

Figure 2. adding code to functions.php file

After updating the file you can check like function wph_auto_alt_title_caption. Therefore upload a new image to the Media library.

Figure 3: Half-filling automatically when adding an image to the Media library

As you can see from Figure 3, the code entered works correctly. All the fields have the same name as well as the added image.

Summary

The provided hook will be very convenient for people who actively blog and upload images to the website every day. It will save your time (especially if you will be adding several images at once) and use it for preparing new articles 😉 .

If you have any questions or comments, please leave comments

Avatar

O Janusz Kaminski

Company marketing specialist TemplateMonster. He has been working in the IT industry for 5 years. He has experience in SEO, internet marketing. Apart from that he is interested in web designing.
  • Internal Links and Sematics

  • Link building
  • Sematics
  • Link building has never been easier. Hundreds of link possibilities in one click.
  • See

[ Article content is protected by Plagiashield ]

SEMRush - the best tool for SEO and PPC.

en_USEnglish
Read previous post:
avatar
How to set a custom profile picture in WordPress?

If you are running a WordPress based website then you have definitely dealt with user comments. This system includes extensive...

Close