• abunile

    (@abunile)


    Hi All,

    I want to add a button exactly below an image, so i can embed image and button together in a body of text.

    Just pasting short code into caption box renders just text view and not the button.I believe the caption box below image allows for html, but I am not a coding guy.

    Would any one have any idea how to do this.

    Thanks for your support

    abunile

    https://ww.wp.xz.cn/plugins/maxbuttons/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Bas Schuiling

    (@basszje)

    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.

    Thread Starter abunile

    (@abunile)

    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.

    Plugin Author Bas Schuiling

    (@basszje)

    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.

    Thread Starter abunile

    (@abunile)

    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

    Plugin Author Bas Schuiling

    (@basszje)

    Thanks. It’s my pleasure to help when I can.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Add short code to Image caption’ is closed to new replies.