Empty P Tags When Using Shortcodes

LovelessDesign said

Do I have to change “the_content” to something else to make it work?

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );
Using [raw] short codes is fine. Removing these filters is absolutely not fine. Doing so causes huge problems for a lot of plugins.

Have you read my problem?
My RAW-tags do not work with shortcodes I’ve implemented like

do_shortcode(ot_get_option( 'textbox1' ));

(With ot_get_option I get the content of a textbox from the theme options)

Hm I really don’t find somehting about it on the www.

mordauk said
LovelessDesign said

Do I have to change “the_content” to something else to make it work?

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );
Using [raw] short codes is fine. Removing these filters is absolutely not fine. Doing so causes huge problems for a lot of plugins.
No worries now Pippin, we're *not approving* themes if they're stripping out native functionalities. @LovelessDesign http://wordpress.org/extend/plugins/shortcode-empty-paragraph-fix/
Ivor said
mordauk said
LovelessDesign said

Do I have to change “the_content” to something else to make it work?

remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );
Using [raw] short codes is fine. Removing these filters is absolutely not fine. Doing so causes huge problems for a lot of plugins.
No worries now Pippin, we're *not approving* themes if they're stripping out native functionalities. @LovelessDesign http://wordpress.org/extend/plugins/shortcode-empty-paragraph-fix/
Thank You for this.
Ivor said

@LovelessDesign http://wordpress.org/extend/plugins/shortcode-empty-paragraph-fix/

Wow, does this really resolve all cases? That’d be cool :slight_smile:

    add_filter('the_content', 'shortcode_empty_paragraph_fix');
    function shortcode_empty_paragraph_fix($content)
    {   
        $array = array (
            '

[' => '[', ']

' => ']', ']
' => ']' ); $content = strtr($content, $array); return $content; }

This plugin does also NOT remove P-Tags for shortcodes I’ve implemented like

do_shortcode(ot_get_option( 'textbox1' ));

I need this kind of implementation because I want to use shortcodes in Theme Options Text boxes.




EDIT: Ok this would work, but isn’t there a nicer solution?

do_shortcode(shortcode_empty_paragraph_fix(ot_get_option( 'fp_textbox' )));
sevenspark said

Wow, does this really resolve all cases? That’d be cool :slight_smile:

    add_filter('the_content', 'shortcode_empty_paragraph_fix');
    function shortcode_empty_paragraph_fix($content)
    {   
        $array = array (
            '

[' => '[', ']

' => ']', ']
' => ']' ); $content = strtr($content, $array); return $content; }

yes but still there’s a major issue: it gets applied to all shortcodes, including those defined in 3rd party plugins (which is bad).

just spent some time on this, and replaced the above with some regexps:

https://gist.github.com/3776987

It basically works the same way but only on your blocklevel shortcodes defined in the array (“col” in the example)

BF

pixelentity said

yes but still there’s a major issue: it gets applied to all shortcodes, including those defined in 3rd party plugins (which is bad).

just spent some time on this, and replaced the above with some regexps:

https://gist.github.com/3776987

It basically works the same way but only on your blocklevel shortcodes defined in the array (“col” in the example)

BF

care to share the full code. did you add it in a filter function?

For what it’s worth, I had been following misguided advice from tutorials that should be taken offline before I ran across this old but useful post by Viper007Bond: http://www.viper007bond.com/2009/11/22/wordpress-code-earlier-shortcodes/

Preprocessing shortcodes that output user-supplied content end up showing correctly without all the annoying paragraph and break formatting issues while third-party plugin shortcodes continue to function normally. I only implemented this recently and so far so good. Anybody have a reason that this is not a good solution?

PixelBook said

care to share the full code. did you add it in a filter function?

yeah, same as quoted example, inside a "the_content" filter

BF

Bookmarked this.

See this thread: http://themeforest.net/forums/thread/double-standards/75528?page=1#644602

I still haven’t found a solution to this after looking through about 5 threads. I am using what I think Pixelentity meant with his last two replies but it isn’t removing the extra junk. Is this code incorrect Pixelentity?

     add_filter('the_content', 'shortcode_empty_paragraph_fix');

    function shortcode_empty_paragraph_fix($content)
    {   
	$block = join("|",array("col"));
	// opening tag
	$rep = preg_replace("/(

)?\[($block)(\s[^\]]+)?\](<\/p>|
)?/","[$2$3]",$content); // closing tag $rep = preg_replace("/(

)?\[\/($block)](<\/p>|
)/","[/$2]",$rep); return $rep; }

(without the weird end p tag that tf adds)

brainbuzzmedia said

I am using what I think Pixelentity meant with his last two replies but it isn’t removing the extra junk. Is this code incorrect Pixelentity?

yes but you need to list in the block array all your block shortcodes like columns, tabs, accordions and similar

$block = join("|",array("shortcode1","shortcode2","shortcode3"));

Erm…how about just this -

p:empty {
display: none;
}

Or, to cover your bases and hide all empty elements,

*:empty {
display: none;
}

murderbydeath said

Erm…how about just this -

p:empty {
display: none;
}

Or, to cover your bases and hide all empty elements,

*:empty {
display: none;
}

None of the PHP solutions have worked consistently for me so I have started using this CSS solution. It works well so far but I'll have to see if the reviewers say anything about it when I upload my next item.

I’ve used this in the past, when I use to bundle shortcodes in my themes and it worked great. They shouldn’t reject you for using these functions, they don’t modify the_content.

function prefix_remove_wpautop( $content ) {
    $content = do_shortcode( shortcode_unautop( $content ) );
    $content = preg_replace( '#^<\/p>|^
|

$#', '', $content ); return $content; }

OR

function prefix_remove_wpautop( $content ) {
    $content = trim( wpautop( do_shortcode( $content ) ) );
    if ( substr( $content, 0, 4 ) == '')
        $content = substr( $content, 4 );
    if ( substr( $content, -3, 3 ) == '

') $content = substr( $content, 0, -3); $content = str_replace( array( '

' ), '', $content ); return $content; }

Usage:

return prefix_remove_wpautop( $content );
StevenGliebe said

For what it’s worth, I had been following misguided advice from tutorials that should be taken offline before I ran across this old but useful post by Viper007Bond: http://www.viper007bond.com/2009/11/22/wordpress-code-earlier-shortcodes/

Preprocessing shortcodes that output user-supplied content end up showing correctly without all the annoying paragraph and break formatting issues while third-party plugin shortcodes continue to function normally. I only implemented this recently and so far so good. Anybody have a reason that this is not a good solution?

This is what Im using too. So far so good. I cant believe how such a big issue can be solved by only adding a number at the end of the add_filter(‘the_content’, ‘do_shortcode’);.

add_filter('the_content', 'do_shortcode', 7);

All

function clean_shortcodes($content) {   
	$array = array (
		'

[' => '[', ']

' => ']', '

[' => '[', ']

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

Works for me.