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.
- Author had a File in an Envato Bundle
- Author was Featured
- Bought between 1 and 9 items
- Europe
- Exclusive Author
- Has been a member for 2-3 years
- Item was Featured
- Referred between 100 and 199 users
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.
OrganicBeeMedia said
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?
Try to return the shortcode with [raw] like this:
function my_shortcode($atts, $content = null){
//your code
return '[raw]'.$your_output.'[/raw]';
}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]';
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.
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
- Attended a Community Meetup
- Author was Featured
- Bought between 50 and 99 items
- Exclusive Author
- Has been a member for 3-4 years
- Item was Featured
- Most Wanted Bounty Winner
- Referred between 500 and 999 users
cudazi said
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
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?
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 );
