Featured Image Alt Text in Dynamic Content

I’m using a custom layout, built in cornerstone, for blog posts. It’s easy for me to set the featured image by assigning it as {{dc:post:featured_image}} however I’ve not been able to figure out how to assign the image the featured image alt text dynamically.

In this documentation on loopers it suggests using the following for the featured image alt text:

“Featured image for {{dc:post:title}} ” for the alt text.

That won’t work for me though as I need it to be the actual alt text for the post’s featured image.

So my two questions are:

  1. What is the meta label of the featured image alt text so I can pull it similar to {{dc:post:featured_image}}?

  2. How could I have figured out the name of the featured image alt text on my own? I can find things like “featured_image” easily enough using the provided options when clicking on the dynamic content links, but even then it’s mostly just trial and error/guess-work. Is there a list somewhere or a methodology I could use in the browser inspector to figure it out?

Screen Shot 2022-04-22 at 9.46.15 AM

Hello @NMWeb,

Thanks for writing to us.

In case you want to display the alt text of the post’s featured image which is stored in the post attachment. Please have a look at the given screenshot below.

Edit-Post-“Prakash-Test”-‹-TEST-—-WordPress

Regretfully there is no option for that at the moment but you can create custom dynamic content code for it to display the alt text of the Post featured image.

 //Use: {{dc:postalttext}}
add_filter( 'cs_dynamic_content_postalttext', function( $result, $field, $args) {
$image_id = get_post_thumbnail_id(get_the_ID(), 'postalttext');
$result = get_post_meta($image_id, '_wp_attachment_image_alt', true);    
return $result;
}, 10, 3 );

You need to add this code in the active child theme functions.php file. Now you need to add the dynamic content code in the Image element ALT text box.

{{dc:postalttext}}

Test-Page-Builder-Pro (74)

Please note that the code provided serves as a guide only and is to help you in getting started so implementing it and maintaining the code will be out of our support scope and for further maintenance for new possible versions of the theme that may cause the customization to break, you will need to hire a developer.

Thanks

2 Likes

Thanks Prakash! I appreciate the thorough answer, the provided solution, and the timeliness of your response!

Hello @NMWeb,

Glad that we were able to help you. Please feel free to open a new thread if you have any more concerns.

Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.