New to Umbraco and we are currently running Umbraco 7, I have just taken over the site from someone else who never added any alt tags to the site imagery.
There are a few thousand images :-(, is there a way I can add the alt tag to the image in the media library and for that alt tag to propagate through every page that image has been used on?
It's actually not easy.
You can add an alt tag in the rendering to all images, but the question is where to get the content for the alt tag?
Do you want to add an editable dynamic alt tag to the CMS for each image?
It's easy to add in code but quite complicated for content managers to add the text for each image.
Hi Alex, thanks for your reply, yes I would ideally like to add an Alt tag field for each image in the media management section, from there out content guys can populate the field.
I have successfully added the new property to the image media type under settings, however how would I adjust how the images render on the page to include this new property?
Unfortunately I added that syntax and the page threw an error which I have listed below.
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1928: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'GetValue' and the best extension method overload 'USNStarterKit.USNHelpers.USNStringExtensions.GetValue(Examine.SearchResult, string)' has some invalid arguments
Adding Image Alt Tags in Bulk
Hi There
New to Umbraco and we are currently running Umbraco 7, I have just taken over the site from someone else who never added any alt tags to the site imagery.
There are a few thousand images :-(, is there a way I can add the alt tag to the image in the media library and for that alt tag to propagate through every page that image has been used on?
Thanks in advance Ben
Hi Ben
It's actually not easy. You can add an alt tag in the rendering to all images, but the question is where to get the content for the alt tag?
Do you want to add an editable dynamic alt tag to the CMS for each image? It's easy to add in code but quite complicated for content managers to add the text for each image.
Thanks,
Alex
Hi Alex, thanks for your reply, yes I would ideally like to add an Alt tag field for each image in the media management section, from there out content guys can populate the field.
Hi Ben
Then it's easy
Just add altText textstring field to image media type in Umbraco.
And adjust image rendering on the page, to get altText you can use GetPropertyValue method on media item
You can share the code snippet and we will adjust it together.
Thanks,
Alex
That's fantastic, thanks Alex, it will be something we are looking at next week so I will be back in touch then.
Thanks again
Are the images named well? We usually grab the name from media as the alt tag.
Image name is not the best alt tag content. Alt tag should describe an image, not show the file name.
Thanks Amir, I don't actually think they are so we would have to add manually.
Correct but you can change the name in the media library to be descriptive without updating the file name.
Great thanks Amir
Hi again guys,
Sorry it's been a while.
I have successfully added the new property to the image media type under settings, however how would I adjust how the images render on the page to include this new property?
Thank you in advance Ben
Hi Ben,
Your image will be of type IPublishedContent so you can get at the alternative text property the same way you would access a document type property:
Where Model is your image property and alternativeText is your alternative text property name alias.
Cheers,
Marc
Hey Marc, how have you been?
Thanks for the reply, the problem I have is I don't know where to add that code, would it be in a file or via the Umbraco interface?
Thanks Ben
The code that outputs your image to a web page is likely within a partial view.
If you can send me the code that is currently outputting your image I can send you the change you need to make to output the alt text.
Thanks Marc, I am trying to dig out the partial view now.
Also just in case you didn't notice it's Ben from Seven Seas Worldwide :-)
I have found the line of code which outputs the image for the pod component which is below:
I have tried to change:
To
But it didn't render as expected.
Hi Ben,
Have you added a field with alias 'altText' to your image media type?
If you have, to get the alternative text value you would use:
Hi Mark
I have indeed added that field to the image media type, I will add your syntax and fingers crossed that should do it.
Thanks Ben
Hi Marc
Unfortunately I added that syntax and the page threw an error which I have listed below.
Any ideas what's causing that error?
Thanks Ben
Hi Ben,
Sorry, I didnt realise you were using Umbraco 7. The correct syntax is:
Thanks Marc, will try that now.
That has worked Marc, thank you!
Great, can you mark the last reply as the answer please.
No problem.
Sorry Marc, one more question, what would be the syntax to access the new "altText" property in the altText variable here:
is working on a reply...