First of all, I have to apologize, my php-skills aren't good enough to solve this myself. So I hope that someone will kindly help me in this matter.
I'm trying to adjust the image caption below single post images. Instead of displaying the caption (post_excerpt), I would like to display the image title (post_title) and image description (post_content). I somewhat got what I'm looking for with the following code:
add_shortcode('wp_caption', 'img_caption_add_description');
add_shortcode('caption', 'img_caption_add_description');
function img_caption_add_description($attr, $content = null)
{
$post_id = str_replace('attachment_', '', $attr['id']);
$img = get_post((int)$post_id);
if (is_a($img, 'WP_Post')) {
$image_title = $img->post_title;
$image_content = $img->post_content;
$attr['caption'] = '<span class="title-css">' . $image_title . '</span><br><span class="description-css">' . $image_content . '</span>';
}
return img_caption_shortcode($attr, $content);
}
Obviously, title and description are only added to the caption as shown here:
How can I replace the caption with the image title and description, thus only showing title and description?
My caption shortcode in the editor looks like this:
[caption id="attachment_214" align="alignleft" width="999"]
<img class="size-full wp-image-214"
src="https://www.[...]/wp-content/uploads/2017/02/geierlay-2.jpg"
alt="Alt Geierlay" width="999" height="749" />
Bechriftung Test[/caption]