wp_get_attachment_caption to pull Image Caption or alt

You can directly get an attachment’s meta data if you have it’s ID. The alt data for an attachment is stored in _wp_attachment_image_alt. So, you can use: $alt = get_post_meta( $attachment->ID, ‘_wp_attachment_image_alt’, true); To get the caption of an image, you can use wp_get_attachment_metadata(). $metadata = wp_get_attachment_metadata( $id ); $caption = $metadata[‘image_meta’][‘caption’]; EDIT Based on … Read more

Add extra class to wp-caption?

Adapted from this answer Add this code to your functions.php file: add_action( ‘after_setup_theme’, ‘wpse_74735_replace_wp_caption_shortcode’ ); /** * Replace the default caption shortcode handler. * * @return void */ function wpse_74735_replace_wp_caption_shortcode() { remove_shortcode( ‘caption’, ‘img_caption_shortcode’ ); remove_shortcode( ‘wp_caption’, ‘img_caption_shortcode’ ); add_shortcode( ‘caption’, ‘wpse_74735_caption_shortcode’ ); add_shortcode( ‘wp_caption’, ‘wpse_74735_caption_shortcode’ ); } /** * Add the new class to … Read more

Get post embedded image caption

If I understood correctly, you are trying to add, to every image embedded in a post gallery, a custom rel attribute and a title attribute based on the attachment caption. Instead of parsing the content, you can try to modify the anchor that wraps the images using the ‘wp_get_attachment_link’ filter. <?php function wpse221533_add_caption_title_to_content_gallery_image_attachments( $markup, $id, … Read more

Get image captions for images on gallery post format metabox

Get the attachment ID and convert to a post. From there the caption is stored on the post object. $thumb_img = get_post( get_post_thumbnail_id() ); // Get post by ID echo $thumb_img->post_excerpt; // Display Caption echo $thumb_img->post_content; // Display Description In your loop it would look like: <?php if($gallery) : ?> <?php foreach($gallery as $key => … Read more

How to show post format gallery metabox image caption in the post front end

You can add to figcaption on your front-end. <?php if ( !empty( $images ) ) { foreach ( $images as $image ) { $image_post = get_post($image); $caption = $image_post->post_excerpt; echo ‘<li class=”animated fadeIn”>’, ‘<figure>’, wp_get_attachment_image( $image, ‘post-full-width’ ), ‘<figcaption>’, $caption, ‘</figcaption>’, ‘</figure>’, ‘</li>’; } } ?>

Nested Shortcode Inside [caption] Doesn’t Process

There is a hook inside the caption shortcode that will allow you to hijack the whole thing. Most of the following is copied from the Core img_caption_shortcode function. function nested_img_caption_shortcode($nada, $attr, $content = null) { extract( shortcode_atts( array( ‘id’ => ”, ‘align’ => ‘alignnone’, ‘width’ => ”, ‘caption’ => ” ), $attr, ‘caption’ ) ); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)