275 posts
  • Affiliate Level 1
  • Author Level 5
  • Romania
  • Collector Level 1
+3 more
DanThemes
says

Thanks for your help. :)

11 posts
  • 4 Years of Membership
  • Author Level 3
  • Collector Level 2
  • Exclusive Author
Matyushen
says


This code is no longer accepted by reviewers:
add_filter('the_content', 'shortcode_empty_paragraph_fix');
function shortcode_empty_paragraph_fix($content)
{   
    $array = array (
        '<p>[' => '[', 
        ']</p>' => ']', 
        ']<br />' => ']'
    );

    $content = strtr($content, $array);

    return $content;
}
What do you guys use instead of it?

We use this instead this little nifty function thanks to bitfade:

https://gist.github.com/bitfade/4555047

This is used because you are only using on your shortcodes so that any 3rd party shortcodes are not affected by this which is why the other code is not allowed, because it also effects 3rd party plugins.

Thanks for the link :)

1 post
  • 5 Years of Membership
  • Collector Level 1
  • Exclusive Author
  • Germany
johannheyne
says

I extended my shortcode_empty_paragraph_fix code for theme developers so it will affect only the defined shortcodes.

function shortcode_empty_paragraph_fix( $content ) {

    // define your shortcodes to filter, '' filters all shortcodes
    $shortcodes = array( 'your_shortcode_1', 'your_shortcode_2' );

    foreach ( $shortcodes as $shortcode ) {

        $array = array (
            '<p>[' . $shortcode => '[' .$shortcode,
            '</p><p>[/' . $shortcode => '[/' .$shortcode,
            $shortcode . ']</p>' => $shortcode . ']',
            $shortcode . ']<br />' => $shortcode . ']'
        );

        $content = strtr( $content, $array );
    }

    return $content;
}

add_filter( 'the_content', 'shortcode_empty_paragraph_fix' );
by
by
by
by
by
by