The alt text is stored as post meta on the attachment, and can be retrieved with get_post_meta() combined with get_post_thumbnail_id():
<?php echo get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true ); ?>
But if you just use the the_post_thumbnail() function then you don’t need to bother, the img tag will be output for you, with the alt text:
<?php the_post_thumbnail( 'post-thumbnail', ['class' => 'vehicle-photo'] ); ?>
Related Posts:
- Restricting users to view only media library items they have uploaded?
- Prevent WordPress from generating medium_large 768px size of image uploads?
- Upload images to remote server
- Separate Media Library for each user
- Media Upload Folder – how to manage
- How to set the default embed image size
- Remove P tags from images
- Filter Media Library by author or post_parent
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- How do i upload an image and return the image id?
- Insert Images at Master Uniform Height
- Alter media caption/description conflict in WordPress?
- Restrict the number of images to upload per post
- Upload images using FTP and show them in media
- Media sizes aren’t being created – server config?
- alt, title tags not showing
- custom image size with New Media Manager in wordpress 3.5
- How to store media files in subdomain
- How to add a media with PHP
- How to make programmatic image upload generate thumbnail and sizes?
- Can’t access ‘Store uploads in this folder’
- How to add qtranslate multi language support for media?
- Best way to strip character entities (%20 etc)
- What’s the best “insert all images” plugin?
- Different upload path per file type
- 3.5 media.editor: what is the event listener for choosing an image?
- Get image alt attribute just by image URL
- Is there a way to get attachment data?
- Rename media files generated during upload
- HTTP Error when uploading files above 7mb unless using GD Image Editor
- How Do I Delete All The Images from WordPress
- Change WordPress Media Manager
- Site migration – some images not displaying in Media Library
- Bulk edit of EXIF data for jpeg images uploaded in the media library?
- Upload media files to Amazon S3
- image in my post disappeared after I upload website to remote server
- Pull images from the gallery
- How can I create more upload paths, like a post corresponding to a post title folder used to store images of the same product
- WordPress automatically downscaled images larger that original
- How to open default wp image editor screen dynamically?
- add media button is not working
- Searching for any images in media library displays “no media found”
- How to filter the image embed code based on link type
- Why it doesn’t show media urls on rest Api? (WordPress)
- How to get file URL from media library
- Change wp-content/uploads to uploads/%postname%/%image%
- Post and featured image have the same name, why is the attachment (image) is showing and not the post?
- Is it possible to change image size used for preview thumnail in Add Media popup
- Generate images to be associated for tag and category?
- Moving media library to the media library of completely different site
- Why does WP allow to view and media item as a page
- Upload media only to DB
- Function to remove all classes on images inserted into posts?
- Get images attached to a specific page
- Why WordPress suddenly changed sizes of thumbnails?
- Is there a way in WordPress to convert images to WebP without a plugin?
- Force default OG:Image – Yoast SEO [closed]
- Is it possible to enable the ‘Link To’ field under ‘Attachment Display Settings’ for a Featured Image?
- Weird encoded error when using wp_generate_attachment_metadata()
- Disable image rename on upload
- How can i identify media uploaded to my website that is not being used anywhere anymore?
- image URL changed in wordpress
- Can’t seem to see images on my machine but can on the server
- Attachments without images
- get rid of random string before an for an image path on wordpress
- Serving Images from subdomain in wordpress
- User uploads image as “Featured Image” but WordPress resizes it?
- Profile image does not upload
- WordPress append -1 to the image name
- Allow a specific user role I have created to only upload one image to his media library
- How to display the Media Library Items Upload date
- Upload error on localhost (at minimum, not yet tested online)
- Built-in image lazy loading: Does it come with a polyfill for older browsers?
- Images not loading on webpage, and links to other media give 404 Not Found
- Updated wordpress missing image upload area
- Post-processing of the image failed
- Generate links on all images in posts – is there a hook?
- Use wget to find used images
- Modify media file markup output
- Unable to delete images in Media Library
- How to regularly backup and update WordPress website with lot of images?
- Newly uploaded images are not updating in featured image
- wordpress images not showing properly
- page displaying media caption shortcodes
- How do I embed youtube video via url in frontend posting
- Missing Images in Uploads Directory (Server Only)
- Set padding for all content except images and few more elements
- Change image link in excerpt to point to post
- Media Library is not loading on grid view in admin panel
- Blurry Images WordPress 5.8.1
- Why some images are not allowed to be edited only for thumbnails?
- problems with alt text not appearing in source code
- WordPress API, creating Featured Media from image url (nodejs)
- Delete all thumbnails & regenerate them?
- Attachment tag archive
- Uploading media to wordpress API with C# HttpClient
- Media Library Issues
- ‘Add Media’ to post – filter images
- How do I display a PDF thumbnail as a link to the PDF without uploading the image
- Featured Image add tab