Weird post formatting with line breaks and empty paragraphs with shortcodes

Support Forums for LiveMesh Themes & Plugins Forums Enigmatic Theme Support Weird post formatting with line breaks and empty paragraphs with shortcodes

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #527
    sba
    Member

    Hi,

    I see some empty <p> tags while using shortcodes. Can you please help me to avoid these. Hope the solution is simple enough.

    #529
    livemesh
    Keymaster

    This is a WordPress issue when using shortcodes. Unwanted line breaks and empty paragraphs are easy to sneak in when designing your content. To help overcome this issue, try to have the following code pasted into your custom-functions.php file –

    /*
    Description: Fix issues when shortcodes are embedded in a block of content that is filtered by wpautop.
    */
    
    function shortcode_empty_paragraph_fix($content) {
        $replace = array(
            '

    ' => '', '

    [' => '[', ']

    ' => ']', ']
    ' => ']', "
    \r[" => "\r[", "
    \r\n[" => "\r\n[", "
    \n[" => "\n[" ); $content = strtr($content, $replace); return $content; } add_filter('the_content', 'shortcode_empty_paragraph_fix');

    .

    Hope this helps.

    #544
    John
    Guest

    Although I didn’t originate the question, I was going to ask it. Perfect solution. Thank you!

    #568
    livemesh
    Keymaster

    The theme was updated last week resolving this issue.

    I still advise users to have this code in there to avoid this annoying WordPress issue when they come up with their content using shortcodes. You can do without this code provided you are willing to spend some time around removing line breaks around shortcode content.

    For demo content, you no longer require this.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Enigmatic Theme Support’ is closed to new topics and replies.