• Resolved Ahmis

    (@ahmis)


    I made a custom shortcode with name “picture”. I made it so I could add two images side by side easily. If I add an image with a caption inside it like this:

    [picture]

    // IMAGE GOES HERE

    [/picture]

    It shows in front end like this:

    caption id=”attachment_xxxxx” align=”alignnone” width=”190″]
    // IMAGE
    This is the caption.
    [/caption]

    Any idea how to solve this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi Ahmis,

    Sounds like an error in your code. Can you provide us with it?

    David.

    Thread Starter Ahmis

    (@ahmis)

    Sure! Here it is:

    function picture ($atts, $content = null) {
         return '<div class="my-class">' . $content . '</div>';
    }
    add_shortcode('picture', 'picture');

    Thanks.

    I see the issue. You’re placing the actual image between the shortcodes but the content being passed is the HTML, but now converted to “safe” characters, hence you’ll find just the code appears.

    You’ll either need to decode the characters back OR re-think how you use the shortcode – e.g. pass the image link as a parameter and get your code to construct the image HTML itself.

    David.

    Thread Starter Ahmis

    (@ahmis)

    Thank you David for your help! I’ll see if I can make this work with your suggestions.

    Thread Starter Ahmis

    (@ahmis)

    If someone is interested I solved it like this:

    function picture ($atts, $content = null) {
         return '<div class="my-class">' . do_shortcode($content) . '</div>';
    }
    add_shortcode('picture', 'picture');
Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Caption shortcode showing front end if inside another shortcode’ is closed to new replies.