
Setup: Copy the function to your functions.php or a code-block!
Output a Custom Image-Caption with the new Bricks Dynamic-Data Function Return Value Option! I’ve created a function for you ready to copy & paste to easily grab some extra information from your featured Image! You would need to add that function either in a CodeBlock, or in your functions.php or if you prefer a Plugin like AdvancedScripts, WPCodeBox or CodeSnippets you can also go with them!
<?php
function getFeaturedImageMeta($type = 'caption'){
if ($type == 'alt'){
return get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true );
} else if ($type == 'title'){
return get_post(get_post_thumbnail_id())->post_title;
} else if ($type == 'description'){
return get_post(get_post_thumbnail_id())->post_content;
} else if ($type == 'caption'){
return get_post(get_post_thumbnail_id())->post_excerpt;
} else {
return 'unknown Parameter';
}
}
?>
Use the Dynamic-Data function return value
To make it work you just need to use Bricks' built in Dynamic-Data, like so. Without passing any parameters it outputs the caption of the featured Image.
You can use the following parameters, which will output the corresponding texts:
{echo:getFeaturedImageMeta}
You can use the following parameters, which will output the corresponding texts:
{echo:getFeaturedImageMeta('alt')}
echo:getFeaturedImageMeta('title')}
echo:getFeaturedImageMeta('description')}
echo:getFeaturedImageMeta('caption')}