Hi,
I’m not sure what a ‘caption box’ is, but I’m guessing you are using some kind of a page / theme builder. You’ll have to ask them if they support including shortcodes somehow, since that’s what we are using to include buttons.
Wow, Thanks for the quick reply Bas,
Sorry I should have made my question a little clearer.
The caption box that I was referring to is the one that appears in WordPress (not Theme Builder) when you click “ADD MEDIA” to a page. After you select your media content on the right hand side there is the box “Attachment details” That where the caption box that I was referring to resides. Below URL and Title.
I believe that box accepts HTML. When I paste button short code in there I just get text appearing.
Hope that is clearer. Should have explained better first time around.
Thanks for your time.
abunile.
Yes, now I understand. I don’t think that’s really going to work like this easily.
I think the easier thing is to add the button in the page/post editor and position it under the image somehow.
I found one way to include the shortcode in the caption, but there is no garantuee this will work with your current theme and probably will need some additional fine-tuning. So if you’re comfortable with a code snippet, this works:
add_filter( 'img_caption_shortcode', 'mb_img_caption', 10, 3);
function mb_img_caption($empty,$attr,$content)
{
$attr = shortcode_atts( array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr );
if ( 1 > (int) $attr['width'] || empty( $attr['caption'] ) ) {
return '';
}
if ( $attr['id'] ) {
$attr['id'] = 'id="' . esc_attr( $attr['id'] ) . '" ';
}
return '<div ' . $attr['id']
. 'class="wp-caption ' . esc_attr( $attr['align'] ) . '" '
. 'style="max-width: ' . ( 10 + (int) $attr['width'] ) . 'px;">'
. do_shortcode( $content )
. '<p class="wp-caption-text">' . do_shortcode($attr['caption']) . '</p>'
. '</div>';
}
This comes from the documentation here, if you want to read more about it.
Thanks for searching that out Bas, I am going to try it.
This really is more than just helpful. It shows a real commitment to your users.
Thanks for that
abunile
Thanks. It’s my pleasure to help when I can.