
Shortcode Empty Paragraph Fix
by Johann Heyne on WordPress.org
Fix known issues when shortcodes are embedded in a block of content that is filtered by wpautop.
(20)
Fix known issues when shortcodes are embedded in a block of content that is filtered by wpautop.
for Theme Developers
If you are developing a theme to provide this on a marketplace, you better embed the following code in your functions.php. This code filters only the shortcodes you defined. Otherwise you risk a failed review because the code in the plugin filters content in general which may is not acceptet.
function shortcode_empty_paragraph_fix( $content ) {
// define your shortcodes to filter, '' filters all shortcodes
$shortcodes = array( 'your_shortcode_1', 'your_shortcode_2' );
foreach ( $shortcodes as $shortcode ) {
$array = array (
'[' . $shortcode => '[' .$shortcode,
'
[/' . $shortcode => '[/' .$shortcode,
$shortcode . ']
' => $shortcode . ']',
$shortcode . ']
' => $shortcode . ']'
);
$content = strtr( $content, $array );
}
return $content;
}
add_filter( 'the_content', 'shortcode_empty_paragraph_fix' );
Another solution that is acceptet at the envato (themeforest) marketplace comes from bitfade.
Active installations1K+
Weekly downloads
27-54.24%
Version0.2
Last updated1/22/2016
WordPress version2.5
Tested up to4.8.25
Tags
fixshortcode