2 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 10+ members
ianmh says

Old post, but in case it helps anyone else, I’m just using the php function strip_tags.

strip_tags($content)

This only works if don’t need html formatting within your shortcodes.

3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

strip_tags – This function tries to return a string with all NUL bytes, HTML and PHP tags stripped from a given str.

If you have a onethird par example shortcode any anchors, bolds, headings or whatever inside will be removed. So this is not a solution.

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

you’ll want to use something like
//Clean Up WordPress Shortcode Formatting - important for nested shortcodes
//adjusted from http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/
function parse_shortcode_content( $content ) {

   /* Parse nested shortcodes and add formatting. */
    $content = trim( do_shortcode( shortcode_unautop( $content ) ) );

    /* Remove '' from the start of the string. */
    if ( substr( $content, 0, 4 ) == '' )
        $content = substr( $content, 4 );

    /* Remove '' from the end of the string. */
    if ( substr( $content, -3, 3 ) == '' )
        $content = substr( $content, 0, -3 );

    /* Remove any instances of ''. */
    $content = str_replace( array( '<p></p>' ), '', $content );
    $content = str_replace( array( '<p>  </p>' ), '', $content );

    return $content;
}

//move wpautop filter to AFTER shortcode is processed
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );

Sorry for the push of this old post.

This code works fine. BUT I also use shortcodes with text areas in the options menu (option tree).

e.g. in the index.php: do_shortcode(ot_get_option( ‘fp_textbox’ ));

How can I also remove the empty p-Tags there?

176 posts
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
+2 more
ThemePrince says

Try to return the shortcode with [raw] like this:

function my_shortcode($atts, $content = null){
//your code

   return '[raw]'.$your_output.'[/raw]';
}
145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

thanks. found the same thing here: http://www.wprecipes.com/disable-wordpress-automatic-formatting-on-posts-using-a-shortcode

But If I use RAW it just types [raw] in the text.

return '[raw]<div class="one-third ' . $align . '">[/raw]'. do_shortcode($content) .'[raw]</div>[/raw]';
176 posts
  • Has referred 100+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 4 years
+2 more
ThemePrince says

Complete shortcode function, put this into function.php:

function my_shortcode($atts, $content = null){
   //your code

   return '[raw]'.$your_output.'[/raw]';
}
add_shortcode("mysc", "my_shortcode");

After that you’ll be able to use [mysc] shortcode in post/page editor.

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

I’ve done it exactly like that. Here’s the whole code:

function lld_one_third( $atts, $content = null ) {
    extract( shortcode_atts( array(
        'align' => ''
    ), $atts));
    return '[raw]<div class="one-third ' . $align . '">[/raw]'. do_shortcode($content) .'[raw]</div>[/raw]';
}
add_shortcode("one_third", "lld_one_third");

And I’ve implemented the code from the link in the functions.php (also tried in the same shortcodes.php). But it still types the [raw] as text

731 posts
  • Has referred 500+ members
  • Has sold $125,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
+7 more
mordauk says

You can also strip formatting by wrapping it in a shortcode like this.

No, do not ever do that. That is one of the worst practices that has plagued WordPress theme development. Covered it a lot over here: http://themeforest.net/forums/thread/wp-theme-forward-compatibility-shortcodescpts/75050

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

The RAW tag works for the shortcodes used in a post or page

But I also use Shortcodes when using Theme Options, e.g. do_shortcode(ot_get_option( ‘fp_textbox’ ));

And then it just types [raw] Texttexttext [/raw]

Do you have a solution for that?

145 posts
  • Has been part of the Envato Community for over 2 years
  • Located in Austria
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
LovelessDesign says

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 );
by
by
by
by
by
by