Skip to content
Advertisement

Get the ALT text of Featured Image

I’m just starting to learn WP coding stuff. Please don’t be too hard on me.

I always see most of the answers for this question are something like or close to this:

JavaScript

I find it hard to convert <?php echo $alt; ?> to something that fits to my code:

JavaScript

I’ve been searching all over the internet for a couple of hours now and hoping to find answers that could possibly work to my code but I still got no luck.

If some of you know how to do this, it will definitely make my day. TIA! 🙂

Advertisement

Answer

After checking my other code snippets, I noticed this different way of using variables.

All I had to do was to change: $data .= '<p><img src="' . get_the_post_thumbnail_url($id, 'full') . '" alt=""/></p>'; to: $data .= get_the_post_thumbnail($id, 'full');


This will be the final code to display WordPress Posts [Title, Excerpt, Learn more (link), Thumbnail/Featured Image, and Tags] using a Shortcode:

JavaScript

Then, add this shortcode [display-featured-item] to any of your page/post.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement