How to add a caption to an image attachment in a file list?

You simply need to pass $attachment_id instead of get_post_thumbnail_id() in echo get_post(get_post_thumbnail_id())->post_excerpt; with wptexturize to prevent your markup from breaking other things. Update: As @birgire suggested I think it is better to use get_post_field() instead of directly accessing post property. Updated code:- function soth_output_gallery_file_list( $file_list_meta_key, $img_size ) { // Get the list of files $files … Read more

Custom field as featured image caption

Here’s one way to inject the custom field as the featured image caption with help of the post_thumbnail_html filter: add_filter( ‘post_thumbnail_html’, function( $html, $post_id ) { if( $html && $caption = get_post_meta( $post_id, ‘wpcf-bildunterschrift’, true ) ) $html .= sprintf( ‘<p>%s</p>’, sanitize_text_field( $caption ) ); return $html; }, 10, 2 ); Hopefully you can adjust … Read more

add_filter img_caption_shortcode not implemented

(gotta read the docs a bit more carefully) I was using this code in the loop $xcontent =get_the_content(); But get_the_content() does not apply filters … as the documentation states (if I was paying attention). I should use the_content(), or change it to this (which is the same as the_content()) : $xcontent =get_the_content(); $xcontent = apply_filters(‘the_content’, … Read more

Displaying caption with featured image

To use this you will need to add this to in place of your themes thumbnail function: function your_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr) { $attachment =& get_post($post_thumbnail_id); if ($attachment->post_excerpt || $attachment->post_content) { $html .= ‘<p class=”thumbcaption”>’; if ($attachment->post_excerpt) { $html .= ‘<span class=”captitle”>’.$attachment->post_excerpt.'</span> ‘; } $html .= $attachment->post_content.'</p>’; } return $html; } add_action(‘post_thumbnail_html’, ‘your_thumbnail_caption’, null, … Read more

Displaying an image’s alt title and caption inside a fancybox window. Working, but showing the same alt and caption for each image

Your problem is with your foreach loops… here: if ($images) { foreach($images as $image) { $caption = $image->post_excerpt; } } and here: //alt title foreach ($images as $attachment_id => $image) { $img_alt = get_post_meta($attachment_id, ‘_wp_attachment_image_alt’, true); } Basically what is happening is that your $caption and $img_alt variables are being set at each iteration of … Read more

How to dynamically insert in the image caption?

That markup is created by the caption shortcode. If you look at the the source for that shortcode you will see this: // Allow plugins/themes to override the default caption template. $output = apply_filters(‘img_caption_shortcode’, ”, $attr, $content); if ( $output != ” ) return $output; That means that you can hook a function into img_caption_shortcode … Read more

Omit image captions from get_the_content()

It turned out that the method called strip_tags(preg_replace(” (\[.*?\])”, ”, $output)) before strip_shortcodes($output), which caused aforementioned issue, since the code removed shortcode in square brackets, but retained contained image captions. I could fix it by swapping the two method calls like this: $output = get_the_content(); $output = strip_shortcodes($output); // Strip WordPress shortcodes first! $output = … Read more

Can’t insert caption into image

I solved it, the problem was a function I used to use and forgot about! add_filter( ‘post_thumbnail_html’, ‘remove_thumbnail_dimensions’, 10 ); add_filter( ‘image_send_to_editor’, ‘remove_thumbnail_dimensions’, 10 ); function remove_thumbnail_dimensions( $html ) { $html = preg_replace( ‘/(width|height)=\”\d*\”\s/’, “”, $html ); return $html; } I removed this function and everything is OK now.

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