439 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says

Hi, everyone! I need to remove wpautop from shortcodes. I use a code by OrganicBeeMedia I have found here:

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

Seems it’s work fine but WP still converts my quotes

'

to #8216

Any help please?

115 posts WordPress Wizard
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Most Wanted Bounty Winner
  • Exclusive Author
  • Envato Studio (Microlancer) Beta Tester
  • Has been a member for 4-5 years
  • Bought between 10 and 49 items
CODE9RS says

I use this in my WPTS that I use in my themes:

/*-----------------------------------------------------------------------------------*/
/* WP Auto Formatting Fix w/Raw shortocde
/*-----------------------------------------------------------------------------------*/

if( ! function_exists( 'wpts_content_formatter' ) ) {
    function wpts_content_formatter( $content ) {
        $new_content = '';
        $pattern_full = '{(\[raw\].*?\[/raw\])}is';
        $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
        $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
        foreach ($pieces as $piece) {
            if (preg_match($pattern_contents, $piece, $matches)) {
                $new_content .= $matches[1];
            } else {
                $new_content .= shortcode_unautop( wptexturize( wpautop( $piece ) ) );
            }
        }
        return $new_content;
    }
}
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_content', 'wptexturize' );
remove_filter( 'the_content', 'shortcode_unautop' );
add_filter( 'the_content', 'wpts_content_formatter', 99 );

With this one, you need wrap the content that will have the wpautop removed with raw

Hope it helps ;D

Cheers, Rafael Angeline

3219 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

I use this in my WPTS that I use in my themes:
/*-----------------------------------------------------------------------------------*/
/* WP Auto Formatting Fix w/Raw shortocde
/*-----------------------------------------------------------------------------------*/

if( ! function_exists( 'wpts_content_formatter' ) ) {
    function wpts_content_formatter( $content ) {
        $new_content = '';
        $pattern_full = '{(\[raw\].*?\[/raw\])}is';
        $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
        $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
        foreach ($pieces as $piece) {
            if (preg_match($pattern_contents, $piece, $matches)) {
                $new_content .= $matches[1];
            } else {
                $new_content .= shortcode_unautop( wptexturize( wpautop( $piece ) ) );
            }
        }
        return $new_content;
    }
}
remove_filter( 'the_content', 'wpautop' );
remove_filter( 'the_content', 'wptexturize' );
remove_filter( 'the_content', 'shortcode_unautop' );
add_filter( 'the_content', 'wpts_content_formatter', 99 );

With this one, you need wrap the content that will have the wpautop removed with raw

Hope it helps ;D

Cheers, Rafael Angeline

thats really really really really really bad practice…..

439 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says

RDever, thanks for your reply, ok, now I have this:

$output .= trim( do_shortcode( shortcode_unautop( $content ) ) );

Could you be bore specific in what I need to wrap a $content? By the way I have disabled converting with this one:

remove_filter('the_content', 'wptexturize');

What do u think? it’s a fine solution?

3219 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

you want to filter your shortcodes that dont need to be texturized through a filter…

add_filter( 'no_texturize_shortcodes', 'your_prefix_no_texturize' );

function your_prefix_no_texturize( $fix_stuff ) {
    $fix_stuff[] = array('make' , 'this', 'a',  'array');
    return $fix_stuff;
}

see wp-includes/formating.php line 60

ps that original code is NOT mine

NOTE : i haven’t tested this and typed it in here so there may be errors

439 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says

OrganicBeeMedia, whta about code that I use, hope it’s ok to use it?

//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 );
remove_filter('the_content', 'wptexturize');
3219 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

OrganicBeeMedia, whta about code that I use, hope it’s ok to use it?

yes see my last post..

the problem with the other code posted it forces users to wrap there post in a shortcode just to make a shortcode work which is extremely bad UX and it can cause a bunch of other problems

2444 posts
  • Has been a member for 5-6 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Envato Studio (Microlancer) Beta Tester
digitalimpact says

This is what I use:

function my_formatter ($content) 
{

    $new_content = '';
    $pattern_full = '{(\[raw\].*?\[/raw\])}is';
    $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
    $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

    foreach ($pieces as $piece) 
    {

        if (preg_match($pattern_contents, $piece, $matches)) 
        {

            $new_content .= $matches[1];

        } else {

            $new_content .= wptexturize(wpautop($piece));

        }

    }

    return $new_content;

}

remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize'); 

// Add filter back, to not strip WordPress core functionality
add_filter('the_content', 'my_formatter', 99);
3219 posts
  • Sold between 5 000 and 10 000 dollars
  • United States
  • Bought between 10 and 49 items
  • Has been a member for 4-5 years
  • Exclusive Author
organicbee says

This is what I use:
function my_formatter ($content) 
{

    $new_content = '';
    $pattern_full = '{(\[raw\].*?\[/raw\])}is';
    $pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
    $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

    foreach ($pieces as $piece) 
    {

        if (preg_match($pattern_contents, $piece, $matches)) 
        {

            $new_content .= $matches[1];

        } else {

            $new_content .= wptexturize(wpautop($piece));

        }

    }

    return $new_content;

}

remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize'); 

// Add filter back, to not strip WordPress core functionality
add_filter('the_content', 'my_formatter', 99);

cough bad practice…

439 posts
  • Bought between 50 and 99 items
  • Europe
  • Exclusive Author
  • Has been a member for 2-3 years
  • Sold between 5 000 and 10 000 dollars
Pixelous says

:)

by
by
by
by
by
by