I uploaded around 600 pictures in different galleries in wordpress without setting the titles and alt attributes. I need to edit them, I was wondering a way to edit them by album, let’s say the title of the pictures in the album soccer would be soccer1, soccer2 etc.. but without doing it manually?
2 Answers
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/