Remove paragraph (<p></p>) tags from widget shortcode

If you add a shortcode in a widget (using the block editor), WordPress will automatically wrap the shortcode in <p></p> tags. This results in an empty space on top of the output of your shortcode.

You can remove the paragraph tags using this filter:

add_filter('render_block', function ($blockContent, $block) {
    if ($block['blockName'] == 'core/shortcode') {
        $blockContent = str_replace('<p>[', '[', $blockContent);
        $blockContent = str_replace(']</p>', ']', $blockContent);
    }
    return $blockContent;
}, 10, 2);

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Overtuigd?

Neem dan contact op voor een offerte of vrijblijvend gesprek.
Stuur een e-mail naar [email protected] of maak gebruik van het contactformulier.