I have a shortcode which accepts basic HTML tags as shortcode attribute.

When this shortcode is used in the shortcode block i.e within <!-- wp:shortcode --> then unbalanced <p> tags are added to the shortcode attribute.

If it is used normally, then no <p> tags are added.

Are there any workarounds which can be done to avoid this issue ?

function abcd_shortcode( $atts ){
    print_r( $atts );
add_shortcode('abcd', 'abcd_shortcode');

enter image description here

Output (notice the </p> and <p> tags added for no reason in the second array)

    [html] => <h4>Hey</h4>Outside

    [html] => </p>
  • This really isn't how shortcode attributes are supposed to work. If you want to accept HTML in a shortcode, use an enclosing shortcode: developer.wordpress.org/plugins/shortcodes/enclosing-shortcodes – Jacob Peattie Oct 21 '20 at 1:34
  • @JacobPeattie Yes I'm aware of that. But any idea why there is a discrepancy between normal and when used inside the shortcode block ? – Aakash Chakravarthy Oct 21 '20 at 18:01
  • @JacobPeattie The idea is that the attribute would accept a basic HTML which the shortcode needs it internally. I agree it is not ideal, but curious to fix it since it works sometimes. – Aakash Chakravarthy Oct 21 '20 at 18:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.