You can use the ‘wp_get_attachment_image_attributes’ hook
add_filter(
'wp_get_attachment_image_attributes',
'image_attributes',
20,
2
);
function image_attributes( $attr, $attachment )
{
// Get post parent
$parent = get_post_field( 'post_parent', $attachment );
// Get post title
$title = get_post_field( 'post_title', $parent );
if ( is_single( $parent ) ) {
$attr['alt']=$title;
}
return $attr;
}
Or Check Out my new plugin
Its now on WordPress plugins directory.
The Alt Manager plugin is a simple plugin that changes images Alt and Title attributes text on your (Pages – Posts) separately to your website name or (post or page) title.This Plugin bulk changes images Alt and Title attributes immediately you dont need to change image info on media library.
https://wordpress.org/plugins/alt-manager/
Related Posts:
- Prevent WordPress from adding image’ title automatically
- How to remove title attribute from gallery links and images
- how automatically show the image title before the image caption/description in a wordpress gallery?
- Show WordPress Image Title Under Custom Portfolio Image
- How do I delete all UNUSED images from my uploads directory?
- get attachment title based on attachment id
- How to extend the gallery block in Gutenberg?
- Overide Gallery Default Link to Settings
- get_post_gallery with Gutenberg
- get_post_gallery_images returns thumbs . I want full size
- Navigate with keyboard in Gallery shortcode
- Cropped featured image replaces original image in gallery
- get images from post and make a zip
- Making WordPress Gallery (.gallery-item) Responsive?
- How do you modify the HTML output of a Gallery item (using the gallery shortcode)?
- How to include externally hosted images into a gallery block
- Adding HTML within an image title attribute
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- Setting up a gallery with images and a zip download
- The WordPress Gallery, Grabbing The Link and Images?
- Displaying a featured image (only img url) as the img src?
- Filter to modify post_title after image upload?
- How to link Gutenberg Gallery images To Media file automatically?
- How to Make WordPress Default gallery responsive on mobile?
- get attributes/part of the gallery shortcode
- Different captions for the same image in multiple galleries. Edit Image in Gallery locally
- Editing built in Gallery shortcode to filter by categories
- Gallery images stored elsewhere (preferably Google Drive)
- WordPress gallery previous/next buttons showing all media library images
- Any way to “combine” galleries or show multiple galleries as one?
- What’s the proper way to use the get_image_tag filter?
- Best option for photo/gallery handling?
- Gallery post images on homepage?
- How to create a simple slideshow out of a post image gallery?
- How to change the target size of images clicked on in WordPress standard gallery
- Get meta data from image
- How to display alt tags in img src?
- WooCommerce-like featured gallery
- Override img class in gallery
- Pull Random Attachments With Pagination
- Extracting gallery images in WordPress 3.5 on index.php
- How to use photo in multiple posts?
- Exclude images from “inserted into post” when trying to get attachments
- Is this post using WordPress Gallery?
- Turn off image captions in gallery view?
- Unyson Framework doesn’t show gallery images
- How can I display an image description, from an image gallery?
- Removing featured image from gallery?
- Creating a post image to show in a gallery
- Don’t show images inserted into content
- Gallery with thumbnail carousel
- Ways to show multiple, separate galleries per post?
- convert post title to image
- How to get the Gallery form/section just like in Gutenberg block?
- Media gallery images url instead of ID on WP API Response
- Get all image IDs from the Media Library
- Re-ordering images in existing post in wordpress 3.6.1
- Autosort uploads in galleries by filename
- How to display original unmodified thumbnail
- One picture belonging different galleries?
- Allow users to contribute images to a post
- How to get the title of the random images from media library?
- limit number of images shown from gallery
- How to automatically populate a gallery with images attached to posts of one category?
- What is the plugin to import image from URL?
- Pagination between images (active/inactive)
- Excluding post thumbnail from the attachment.php when using wordpress gallery
- photo gallery implementation like tmz
- How do I display the featured image from an image gallery using a reference in code? (example within)
- Can i have 2 separate Galleries on 2 separate pages each go to a DIFFERENT Attachment.php file?
- How to enlarge thumbnail on mouseover?
- attach several images to post + gallery
- get_post_gallery with Gutenberg
- Allow users to upload and display multiple photos
- Implementing a modal(lightbox) for all images in all post-gallery posts
- Link to products with the same image title (woocommerce)
- change the h3 subtitles of the wordpress gallery shortcode
- get_the_post_thumbnail() title and alt attributes not displaying
- How to re-arrange images in default WP Gallery more than one image at once?
- get_post_gallery with Gutenberg
- How to automatically load an image inside the post, since it is present in uploads folder
- How do i replace the title attribute of img tag with the image caption
- Replacing an Image gallery
- attachment.php & flexslider—linking thumbnail to specific image
- Thumbnail gallery by date and taxonomy
- Breadcrumbs for Single Image page
- Thickbox not displaying just the image, instead showing full page in lightbox
- Multiple gallery thumnbnails on one page
- Putting the title attribute in image tag — Snapshot Theme from Woothemes
- Slider do not add alt attribute. Cant get alt attribute from a media library!
- wp_get_attachment_link() add rel attribute if the link points to direct image
- Paginate Gallery [closed]
- How do I set the sizes of my thumbnails when inserting a [gallery]?
- *box for images displayed as a post’s [gallery] [duplicate]
- Display X images from a gallery in the sidebar
- Getting top Image From the Gallery and printing out a thumbnail with Exact Dimensions
- Adding different classes to different images depending on size for fine control of image layout in posts
- Display image title and caption inside a single post
- Automatically adding blog images to a portfolio/gallery
- Image Attachments Query Not Working If Post Is Loaded Via Ajax