My sincere apologies if the following is completely way off as I'm new to this.
From what I can tell, I need to be working with wp_get_attachment_image
to inject the alt and title text for every image in every post.
My theme is loading in post content with the_content();
, and after looking at the Wordpress Developer page for the_content();
I'm guessing that this function is calling post-template.php
.
The only section I can find in post-template.php
that contains wp_get_attachment_image
is as follows:
if ( $text ) {
$link_text = $text;
} elseif ( $size && 'none' != $size ) {
$link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $attr );
} else {
$link_text = '';
}
After looking over this answer, I'm guessing I need to do something like this with the above code:
if ( $text ) {
$link_text = $text;
} elseif ( $size && 'none' != $size ) {
$image_alt = get_post_meta( $image->id, '_wp_attachment_image_alt', true);
$link_text = wp_get_attachment_image( $_post->ID, $size, $icon, $image_alt );
} else {
$link_text = '';
}
I've passed the variable $image_alt
in place of $attr
here.
Again, I imagine this is very wrong, and my apologies.
wp_get_attachment_image()
won't be involved. That function is for use in templates.