Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Randomly Assign an Image’s Alt Text Based on Data From Post

Just set the image alt text when the image is saved. Hook onto the save_post action, check if any of the attached images don’t have alt text, and if not then generate the alt text you want and save it with:

update_post_meta( $attachment_id, '_wp_attachment_image_alt', 'this is the alt text' );

Related Posts:

  1. How to Display Image Meta underneath EVERY image in EVERY post
  2. Show all terms of a custom taxonomy?
  3. How to update custom fields using the wp_insert_post() function?
  4. How do I change/modify the_post_thumbnail(); html output?
  5. What’s the best way to use the Featured Image for responsive web design?
  6. How to Add Custom Fields to Custom Taxonomies in WordPress CLEANLY
  7. Get meta_id along with meta_key and meta_value
  8. Creating custom Woocommerce attribute taxonomies from a plugin
  9. How to paginate a list of custom taxonomy terms?
  10. How can merge two arrays values in one array and save in database
  11. Check if user already visited this post today
  12. Display all meta for a post?
  13. PHP/Manual use of images? – 2 Questions
  14. How to display multiple Post meta_key/meta_values by SQL query
  15. the_post_thumbnail() based on the Post ID
  16. How to use multiple query with same meta key
  17. How to update single value in multi dimensional Post Meta?
  18. WP_Query | Help me create a search term with an ‘OR’ relation?
  19. Adding Featured Image to Post programatically
  20. Get used terms by an author as array of strings
  21. How to upload imagick resource to media in wordpress
  22. How to add a featured image to a existing post via php?
  23. How to use SRCSET with get_the_post_thumbnail()?
  24. How to get the term before the last from a custom taxonomy?
  25. Why is my get_post_meta always empty
  26. Compare two meta key values against each other inside the get_posts array?
  27. How can update custom meta for all posts
  28. How to create filterable portfolio in WordPress?
  29. Adding featured image via PHP
  30. WordPress loop specific thumbnail size
  31. WP_Query use for a filter with multiple Taxonomies and Terms
  32. How do I get images (with a thumbnail preview) to show in search results?
  33. Use ajax to update_post_meta
  34. fallback image for featured image
  35. Display Post co-authored in Author Page
  36. How to get Poster (thumbnail) Image of Video
  37. Include a specific post to the query_posts and remove it if it is already in the returned list
  38. WP Insert Post function – Insert Post Thumbnail
  39. Display All Post Attachments and Assign Class to the Last Image?
  40. How to make thumbnail image fit into a div where image dimentions are completely different?
  41. Add attribute / custom attribute to product in woocommerce
  42. Assign a picture URL to a page via PHP
  43. How to add custom taxonomy slug in CPT permalink?
  44. How to scale image with equal width and height without distortion?
  45. Show Custom Taxonomy Title
  46. Featured image fallback link to permalink
  47. conditional statement for custom taxonomy
  48. is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
  49. how to increase custom post value by one most efficiently?
  50. Batch update a post meta field value of each post in Post Type
  51. How can I show the post thumbnail from the most recent of a certain post type, in widget?
  52. get_the_terms – only top level
  53. Change description on specific WooCommerce product status change
  54. How can I add pagination and how can I change thumbnail size?
  55. Get Custom URL For Custom Taxonomy
  56. get_terms orderby numeric
  57. Use WP_Query in shortcode
  58. Rename “Portfolio” slug?
  59. Sum custom field values of particular taxonomy
  60. Echo URL of large version of Featured Image
  61. Query all posts of a custom taxonomy term
  62. Get Current User Id Inside a Loop Returns 0 For a Shortcode
  63. Random order of WP_Query results with highest meta value
  64. How to stop featured image thumbnail [set as background image] on blog index page just repeating same image across all posts
  65. Values inside a custom field to determine which category posts to display
  66. Get category id for a custom category and display it in a class
  67. retrieve wordpress post-meta using php not wordpress functions
  68. Saving category as insert post
  69. How to show all of aspecific post type that has taxonomy and a specific term
  70. Postmeta not saving
  71. If custom field doesn’t exist, or exists and it’s true show title?
  72. Overwriting a Shortcode
  73. featured post as div background
  74. How to display thumbnail if post is assigned one otherwise not
  75. Pass custom value to custom taxonomy
  76. Post Thumbnail on Single (if elseif else)
  77. get_post_meta is always empty when I use wp_mail
  78. the_post_thumbnail unless video id is added
  79. get_post_meta no longer working
  80. Query specific posts per user selections from dropdown menus
  81. Setting post thumbnail sizes in template file and functions.php
  82. How to add together (get the sum) a field from all author’s posts
  83. Metadata on the WP_Post object
  84. How to display the date under the post title?
  85. How can i give a download link to the thumbnail or featured image
  86. add if statement to the featured image
  87. How to crop featured image in different sizes?
  88. Remove default Image Sizes
  89. How do I change the Go To Categories link in the term_updated_messages
  90. Display terms on product page with shotrcode
  91. Add attribute to featured image with filter (wp_get_attachment_image_attributes)
  92. Query posts by custom taxonomy slug in WP REST API?
  93. How can I change the URL via add_rewrite_rule()
  94. Generate and upload screenshot as featured image for user-submitted post
  95. How do I get a function to work in single.php
  96. WordPress different custom tag being displayed in on tag list
  97. Get category name of current post (CPT UI)
  98. Three different queries on same page
  99. I want to show image from custom field image on my custom page template
  100. How do I organize posts based on their taxonomy?
Categories PHP Tags custom-taxonomy, php, post-meta, post-thumbnails
How to append to title via functions.php for auto-posting plugin [duplicate]
What is the correct way to update both WP/plugins/themes without breaking the site?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress