- Sold between 250 000 and 1 000 000 dollars
- Exclusive Author
- Community Moderator
- Author was Featured
- Bought between 10 and 49 items
- Referred between 200 and 499 users
- Has been a member for 4-5 years
- Won a Competition
/*-----------------------------------------------------------------------------------*/
/* Shortcodes clean up - prevents the empty paragraph at the top of the shortcode
/*-----------------------------------------------------------------------------------*/
// clean up shortcode
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 );
I have used it in few of my themes and everything was fine. But now with my new theme the reviewer said that he wont accept my theme with this code
So my question is there any other solution to avoid those empty p and br tags? What do you think about this?
- Microlancer Beta Tester
- Sold between 5 000 and 10 000 dollars
- Most Wanted Bounty Winner
- Bought between 10 and 49 items
- Exclusive Author
- Has been a member for 2-3 years
why WP core is inserting empty tags??? WordPress dev guys should fix this ASAP
Hmm…. Don’t have sure if the reviewers are the real idiots and amateurs here…. hahahahahhaa
The reviewers have a big experience and I think you should respect it…
The reviewer is doing the write thing, this kind of code @mpc modifies the default behavior of WP filters. You can’t do it, if you do, some popular plugins can’t work fine.
I’m using this code now:
add_filter('the_content', 'shortcode_empty_paragraph_fix');
function shortcode_empty_paragraph_fix($content)
{
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
return $content;
}
Add this to your functions.php for example.
This one it’s fine, because doesn’t strip any default filter, only add a additional filter what is acceptable.
I hope it helps 
^^ Got there before me, that’s the code we use too 
- Ed
You really don’t need the whole parse_shortcode_content function as you don’t use it anywhere. The shortcode_unautop function is part of core WordPress filters, but somehow it is not applied or applied before wpautop filter. For shortcodes to work properly you only need the three last lines of your code.
I use it in my themes and it works great. The thing with this piece of code is that some plugins use different methods of cleaning up shortcode content and this method interferes with said plugins. Few of my customers have contacted me about the issue, I then told them to comment out the three lines and let plugins clear the shortcodes their way.
I can see why reviewers would reject code that messes with default WordPress functions and filters, but they just see the remove_filter line, not the whole picture. You are just moving the filter priority around and that will not cause any issues (apart form the one described above, but plugins are to blame for this too).
@kaaz This has been around for as long I can remember and I have no idea why it hasn’t been fixed yet. 
@RDever Your code looks promising, I’ll give it a try! 
- Has been a member for 3-4 years
- Attended a Community Meetup
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Bought between 50 and 99 items
- Canada
- Community Ambassador
- Beta Tester
- Contributed a Tutorial to a Tuts+ Site
- Envato Staff
You got to take a bit of a chill pill xstortionist
You know the forum rules about calling down hate on the reviewers, let’s try and keep things constructive.
Hi @pogoking.
The last 3 lines are the problem hahahaha you can’t (you SHOULDN ’T) remove and move the order of the filters.
This is a core modification, when you just add a filter, it’s fine, but when you remove and change the order, it isn’t…
Themes are the visual part of the WP installation and should be our mission don’t break any plugin… a CSS rule missing or styling issue it’s okay, but totally break the plugin isn’t ok to the users.
Yes, give a try. I’m getting great results with this code 
Cheers, Rafael Angeline
- Sold between 100 000 and 250 000 dollars
- Won a Competition
- Author was Featured
- Item was Featured
- Referred between 500 and 999 users
- Author had a Free File of the Month
- Author had a File in an Envato Bundle
- Bought between 10 and 49 items
RDever saidthis still gets applied to all shortcodes, including 3rd party ones and alters formatting for “inline” scs. Other authors got rejected by using this code too.
add_filter('the_content', 'shortcode_empty_paragraph_fix'); function shortcode_empty_paragraph_fix($content) { $array = array ( '<p>[' => '[', ']</p>' => ']', ']<br />' => ']' ); $content = strtr($content, $array); return $content; }
You’re right, but the only reason why I used to rearrange filters was because all the other code snippets around the internet didn’t work. Your code seems to work great, just have to test if it works in all the cases (e.g. if you put the shortcode in separate line vs on the same line as it’s content but with a space in between). Cheers and thanks for the tip!
EDIT : @pixelenity So what do you suggest? What do you use?
- Community Superstar
- Item was Featured
- Author was Featured
- Has been a member for 5-6 years
- Won a Competition
- Sold between 50 000 and 100 000 dollars
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- Europe
What about js? Search with it the empty paragraphs or br tags in forbidden areas and remove them. Is that allowed? 
