Search code examples
wordpresstinymceshortcode

Shortcodes get wrapped with p tags


I would like to insert some shortcodes in the wordpress editor (v 3.3+)

The string looks like

[a_col]<p>some text or other stuff</p>[/a_col]

which is fine but if i use this line in JS

tinyMCE.get('content').setContent(string);

my shortcodes get surrounded by p tags which looks like

<p>[a_col]</p><p>some text or other stuff</p><p>[/a_col]</p>

I really don't like to touch native functions. Maybe there is a different solution to insert content


Solution

  • Here is my solution:

    the shortcode function returns

    <div class="col a">'.preg_replace('#^<\/p>|<p>$#', '', do_shortcode($content)).'</div>
    

    this removes all unwanted p tags