How to add wordpress media within enclosing shortcode

I’ve successfully created an enclosed shortcode to wrap CSS3-column divs around articles in WordPress.

Attempts to add images using the media library fail.

Researching the issue, I find this statement on the WP codex:

https://codex.wordpress.org/Shortcode_API

The shortcode parser uses a single pass on the post content. This means that if the $content parameter of a shortcode handler contains another shortcode, it won’t be parsed:

[caption]Caption: [myshortcode][/caption]
This would produce:

Caption: [myshortcode]
If the enclosing shortcode is intended to permit other shortcodes in its output, the handler function can call do_shortcode() recursively:

function caption_shortcode( $atts, $content = null ) {
return ‘’ . do_shortcode($content) . ‘’;
}
How do I overcome this? The client needs to be able to use the Media Library to insert images.

Here is my working shortcode:

function twocolumn_function($atts, $content = null) {
return '<div class="columns02">' . do_shortcode($content) . '</div>';
}

add_shortcode('2columns', 'twocolumn_function');
the CSS is simple CSS3 columns in media queries.

My skills are limited and I’m stumped. Please help.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.