Woocommerce Gallery Image Caption: Use “caption” — not “alt tag”. Keep alt tag as is

Phew! Here is the code for functions.php. add_filter( ‘woocommerce_single_product_image_thumbnail_html’, ‘change_alt_to_caption_gallery_images’, 10, 2 ); function change_alt_to_caption_gallery_images ( $wc_get_gallery_image_html, $image_id ){ $caption = get_post_field( ‘post_excerpt’, $image_id ); if ( !empty($caption) && !empty($wc_get_gallery_image_html) ) { $caption = str_replace( ‘”‘, “””, $caption ); $caption_repl=”data-caption=”” . $caption . ‘”‘; $wc_get_gallery_image_html = preg_replace( ‘/data-thumb-alt=”[^”]+”/’, $caption_repl, $wc_get_gallery_image_html ); } return $wc_get_gallery_image_html; }

PHP Fatal error: Uncaught TypeError: Cannot access offset of type string on string in Stack trace:\n#0 [internal function]: img_caption_shortcode()

You’re mis-using the caption shortcode here You can fix it by adding a width option, which is required per the official documentation In any case, this is also likely a bug in WordPress (misusing a shortcode shouldn’t result in a PHP Fatal Error). See the following bug report: https://core.trac.wordpress.org/ticket/59206

Add custom text before all image captions in WordPress posts

You can filter the image caption using the wp_get_attachment_caption filter: add_filter( ‘wp_get_attachment_caption’, ‘wpse422651_filter_image_caption’, 10, 2 ); /** * Filters the image caption. * * @param string $caption The image caption. * @param int $attachment_id The attachment ID. * @return string The filtered caption. */ function wpse422651_filter_image_caption( $caption, $attachment_id ) { // Only run if the … Read more

Customize all image captions

Depending on whether the captions are using the same CSS class or HTML tag, you can add a :before pseudo element to the CSS. This will add an image before every <caption> tag on your website. caption:before { content: ”; display: inline-block; background: url(‘your-image-url-here’); background-repeat: no-repeat; background-size: contain; background-position: center center; height: 15px; width: 15px; … Read more

Adding caption to all images inside an article

I’m not 100% sure if I understand your question 100%, but WordPress, by default, displays the caption if it’s filled on the image. Then it displays it just below the image once the image is inserted. Here is an example where I just filled it out on one image 👇

How to display featured image caption only if exists?

I am a “little late” but this solution worked great for me. It will show the div only if the caption is not empty. <?php $get_description = get_post(get_post_thumbnail_id())->post_excerpt; the_post_thumbnail(); if(!empty($get_description)){//If description is not empty show the div echo ‘<div class=”featured_caption”>’ . $get_description . ‘</div>’; } ?>

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