The theme just inserts the first image attached to the post. I was hoping it was just a matter of adding an extra line of code somewhere to insert the title of the image in the ALT tag.
I saw elsewhere that usually it's as simple as adding:
alt="<?php the_title() ?>"
But where would I put that in the code below?
Here's the theme code from the functions.php file:
// Post Attachment image function. Image URL for CSS Background.
function the_post_image_url($size=large) {
global $post;
$linkedimgurl = get_post_meta ($post->ID, 'image_url', true);
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo ''.$attachmenturl.'';
}
} elseif ( $linkedimgurl ) {
echo $linkedimgurl;
} elseif ( $linkedimgurl && $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo ''.$attachmenturl.'';
}
} else {
echo '' . get_bloginfo ( 'stylesheet_directory' );
echo '/img/no-attachment.gif';
}
}
// Post Attachment image function. Direct link to file.
function the_post_image($size=thumbnail) {
global $post;
$linkedimgtag = get_post_meta ($post->ID, 'image_tag', true);
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo ''.$attachmentimage.'';
}
} elseif ( $linkedimgtag ) {
echo $linkedimgtag;
} elseif ( $linkedimgtag && $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
{
foreach( $images as $image ) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo ''.$attachmentimage.'';
}
} else {
echo '<img src="' . get_bloginfo ( 'stylesheet_directory' ) . '/img/no-attachment-large.gif" />';
}
}
//Setup Images for Attachment functions
function image_setup($postid) {
global $post;
$post = get_post($postid);
// get url
if ( !preg_match('/<img ([^>]*)src=(\"|\')(.+?)(\2)([^>\/]*)\/*>/', $post->post_content, $matches) ) {
return false;
}
// url setup
$post->image_url = $matches[3];
if ( !$post->image_url = preg_replace('/\?w\=[0-9]+/','', $post->image_url) )
return false;
$post->image_url = clean_url( $post->image_url, 'raw' );
delete_post_meta($post->ID, 'image_url');
delete_post_meta($post->ID, 'image_tag');
add_post_meta($post->ID, 'image_url', $post->image_url);
add_post_meta($post->ID, 'image_tag', '<img src="'.$post->image_url.'" />');
}
add_action('publish_post', image_setup);
add_action('publish_page', image_setup);
// Post Attachment image function for Attachment Pages.
function the_attachment_image($size=large) {
$attachmenturl=wp_get_attachment_url($image->ID);
$attachmentimage=wp_get_attachment_image( $image->ID, $size );
echo ''.$attachmentimage.'';
}