I am having trouble dynamically creating an alt tag for an image while in the loop. I am pulling a posts custom field (where I have stored the url to the image) to create the <img> source. here is a snippet of code.
// In The Loop ... <?php echo '<img class="thumb" src="'.get_post_meta($post->ID, 'post_image', TRUE).'"/>'; ?> ...
This works to create the image. However, my “/” use for self cloing the <img> tag is stripped off.
But, when I add something like this below it does not work.
// In The Loop
<?php echo ‘<img class=”thumb” src=”‘.get_post_meta($post->ID, ‘post_image’, TRUE).'” alt=”‘.the_title().'” />’; ?>
When the code executes, it places the info from the function the_title() in front of the <img> tag. My source looks like the following:
text from the_title function<img class=”pic” src=”pictureURL” alt=”” >
Hope someone can help me with this.
- The topic ‘Can’t create an Images alt tag in The Loop’ is closed to new replies.