Community Forums › Forums › Archived Forums › General Discussion › Check if Image Caption is Empty and Show Description
Tagged: image captions, image descriptions
- This topic has 2 replies, 1 voice, and was last updated 10 years, 2 months ago by jameswray.
-
AuthorPosts
-
February 18, 2014 at 5:23 am #90931February 18, 2014 at 7:42 pm #91051jameswrayMember
Ok so someone elsewhere has given me hand with some of the code needed to do this, though I actually think probably a simpler way as well.
Anyway,
he said add this code to you loop.
<?php $args = array( 'post_type' => 'attachment', 'orderby' => 'menu_order', 'order' => 'ASC', 'post_mime_type' => 'image' ,'post_status' => null, 'numberposts' => null, 'post_parent' => $post->ID ); $attachments = get_posts($args); if ($attachments) { foreach ( $attachments as $attachment ) { $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true); $image_title = $attachment->post_title; $caption = $attachment->post_excerpt; $description = $image->post_content; ?>
Then find the place in your theme's directory ( probably in single.php ), with this markup, for the caption text;
<p class="wp-caption-text"> .... </p>
Within those two html tags, take out the existing code and or makup, and add;
<?php if ($caption!=""){echo $caption; } else { echo $description; } ?>
Now this all looks quite straightforward code and normally I'd have no trouble editing some php files or templates. However, I cannot for the life of me work out where this is even if I wanted to change the core files, which I don't. Now I know I can remove the Genesis loop and add my own stuff, but does that mean I have to form the whole post content? Should the first bit of code be a function that replaces something via some hook? I could not find any mention of captions anywhere in the hooks or filters etc.
Some guidance on this would be welcome. Spending a lot of time trying to do some pretty simple things.
Thanks
JamesFebruary 19, 2014 at 9:08 am #91140jameswrayMemberWell I guess not going to get any help.
Anyone sort this for a fee?
Cheers
James -
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.