Bulk edit wordpress images alt and title attributes

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/

Leave a Comment

error code: 523