Dans le cas l’on l’on veuille ajouter des choses particulières au contenu du champ de la légende d’image.
Où placer le code ?
Dans le fichier functions.php
de votre votre thème enfant.
add_filter( 'img_caption_shortcode', 'captionhtml', 10, 3 ); function captionhtml($current_html,$attr,$content) { extract(shortcode_atts(array('id' => '','align' => 'aligncenter','width' => '','caption' => ''),$attr)); if ( 1 > (int) $width || empty($caption) )return $content; if ( $id ) $id = 'id="' . esc_attr($id) . '" '; // On ouvre le caption $out ='<div '.$id.'class="wp-caption '.esc_attr($align).'" style="width:'.(10 + (int) $width).'px">'; // L'image $out .= do_shortcode($content); // La légende $out .= 'Essai : '.$caption.'</p>'; // On ferme le caption $out .= '</div>'; return $out;}
Source – https://www.seomix.fr/caption-image/