Include captions

st Note: // Prepare the code for safety $images = $wpdb->get_col( $wpdb->prepare( ” SELECT ID FROM %s WHERE post_type=”attachment” AND ID IN ( %s ) ORDER BY menu_order ASC “, $wpdb->posts, $meta ) ); nd Note: Look into what you already got: // Inside the foreach loop echo ‘<pre>’; var_dump( $att ); echo ‘<pre>’; rd … Read more

Adding a video description in a similar way to a image caption

It will be interesting to see how the new evolving WP Gutenberg editor will handle shortcodes and embeds. If you use the shortcode for embedding, then a semi workaround, without UI support: where the custom desc attribute is supported with with this kind of wrapper: add_filter( ’embed_oembed_html’, function( $return, $url, $attr ) { if( ! … Read more

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