381 posts Keep Walking
  • Has been a member for 3-4 years
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 100 and 499 items
  • Referred between 100 and 199 users
  • Exclusive Author
UXbarn says

Hi,

I’m having an annoying problem with auto p tag that wraps around the shortcode. I’ve searched for many ways to solve this but I’m not sure which one is valid and can be accepted.

I’m currently using this:
add_filter('the_content', 'do_shortcode', 7);

But it only works for some cases. “p” tag is still there on some element, don’t know why.

Then I’ve found this:
function clean_shortcodes($content) {   
    $array = array (
        '<p>[' => '[', 
        ']</p>' => ']',
        '<p><span>[' => '[', 
        ']</span></p>' => ']', 
        ']<br />' => ']'
    );

    $content = strtr($content, $array);
    return $content;
}
add_filter('the_content', 'clean_shortcodes');

This one actually works. It can solve my problem but I think I used to read from some where that it would not be accepted? Not sure if I’m wrong…

Could you guys advise what solution are you using and valid for this case?

Thanks!

1400 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says
381 posts Keep Walking
  • Has been a member for 3-4 years
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Bought between 100 and 499 items
  • Referred between 100 and 199 users
  • Exclusive Author
UXbarn says

Thanks @OriginalEXE! Will try that. :)

by
by
by
by
by
by