SEO Friendly Images for tags

Posted in: Newspaper
Post count: 67

Hello Newspaper community,

We are looking for a method to automatically add the image title of the uploaded photos to the alt tag for SEO purpose. We are trying this plugin:

https://wordpress.org/plugins/seo-image/

But it is not working. Do you know why? Is there any method to add automatically the same title of the images to the alt tag?

Thank you in advance.

Post count: 555

Hey add this code to the bottom of ur “functions.php file” you don’t need a plugin to do this….it work because i’m using it on my site this code..

function add_alt_tags($content)
{
global $post;
preg_match_all(‘//’, $content, $images);
if(!is_null($images))
{
foreach($images[1] as $index => $value)
{
if(!preg_match(‘/alt=/’, $value))
{
$new_img = str_replace(‘<img’, ‘post_title.'”‘, $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
}
return $content;
}
add_filter(‘the_content’, ‘add_alt_tags’, 99999);`

  • This reply was modified 11 years by Steven.
Post count: 6600

Thanks @Steven for your help!

Post count: 67

Hi Steven. You are great!
I understand that with this code, the Title of the image will become automatically the Alt Tag. Does it affect to all the images in the website or just the new ones?
Thank you again.
And as always, thank you Lucian for your attention.

Post count: 555

Ur both welcome,


@monicacortes
what the code really do is add a Alt Tag automatically to all images that don’t have any,if you have uploaded images already that don’t have the Alt Tag the code will add it to those images automatically also any new ones you uploaded after.

Post count: 67

Hello, Steven and Lucion.

I’m sorry but this code is not working. We are adding it to the bottom of our theme Functions.php and the website stop working.

Any advice?

Thanks.

Post count: 6600

Hi,

Please use this:http://pastebin.com/bgBTmhen and add it in your functions.php file like this: http://screencast.com/t/VmomvTMTLJ
I have tested it and it works so it should work fine for you also just make sure you add it right.

Thanks

Post count: 67

Done, Lucian.

I was doing it in the child theme. But I suppose I have to do it in the main theme folder.

Just one question. With this code, when there is an image with no alt tag, the title of the post is included as alt tag. Is there anyway to change it and put the same title than the image, instead of the title post?

Thank you very much.

Post count: 6600

Hi,

First please make sure you make a copy of the td_module.php file so you can revert to it if something goes wrong.
After this please edit the file and replace this two lines: http://screencast.com/t/NvxxCx1s with this code: http://pastebin.com/LBKa1S1i
This will add the image/attachment/thumb title to the alt tag but this will add the image title for all images and if you want this only for those images that lack an alt tag you need to modify it or get someone to help you with it if you don’t know how to do it as this means custom work and unfortunately we don’t have the resources to offer custom work at this time.
You can also use the previous code and adjust it as you like.
I have also tested this: http://screencast.com/t/VzhCt9euB

Thanks

Post count: 67

Hello Lucian,

This last solution seems very complicated.

We have added the first code, in order to add the post title to the alt tag of the images when it doesn’t exist.

We have added it to the original functions.php file (not in the child theme function.php file).

But as you can see in the code of this old page, is not working:

view-source:http://marronyblanco.com/secadora-prosteam-aeg/

How can we solve it?

Thank you in advance.

Post count: 6600

Hi,

Should work, I have tested it, just make sure you do it like this: http://screencast.com/t/41D68wKZs

Thanks

Post count: 67

Hi Lucian,

So, in addition of the functions.php code, I have to modify this td.module.php file?

Sorry for my ignorance.

Post count: 6600

Hi,

You don’t need any change into the functions file, just do this: https://forum.tagdiv.com/topic/seo-friendly-images-for-tags/#post-26533

Thanks

Post count: 67

Simply amazing, Lucian! It works like a charm.
I think is a good SEO functionality.
Maybe you could consider to add it in the next update of the theme: if the user add manually an ALT tag, it has priority. But if the user forgets to add it, the theme could add automatically the name of the image file to the ALT tag. It’s better than nothing, isn’t it?

Once again, thank you for your incredible support.
Mònica.

Post count: 6600

Glad you managed to do it, we will also consider it for future updates!
Thanks for the message!

Viewing 15 posts - 1 through 15 (of 15 total)
The forum ‘Newspaper’ is closed to new topics and replies.