Opened 2 months ago
Last modified 2 months ago
#62694 new defect (bug)
wpautop Misuse in the "widget_block_content" Filter with Shortcode Block
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.7.1 |
Component: | Widgets | Keywords: | needs-patch |
Focuses: | Cc: |
Description
The widget_block_content
filter introduces invalid HTML when processing content from the Shortcode block. Specifically, when a shortcode returns a block-level element like a <div>
, it is improperly wrapped in <p>
tags, resulting in invalid markup.
Steps to Reproduce
- Create a simple shortcode in your theme or plugin:
<?php add_shortcode( 'my_test_shortcode', function() { return '<div>something amazing...</div>'; } );
- Go to Appearance > Widgets in the WordPress admin area.
- Add a Shortcode block and use
[my_test_shortcode]
as its content.
- Save and view the output on the front-end. Notice that the
<div>
returned by the shortcode is wrapped in<p>
tags, resulting in:something amazing...
Expected Behavior
The shortcode output should render the block-level <div>
without additional wrapping <p>
tags, maintaining valid HTML structure.
Proposed Solution
Consider modifying the widget_block_content
filter to handle shortcodes correctly and respect block-level elements, preventing improper wrapping by wpautop
.
Change History (2)
#2
@
2 months ago
- Summary changed from Title: wpautop Misuse in the "widget_block_content" Filter with Shortcode Block to wpautop Misuse in the "widget_block_content" Filter with Shortcode Block
Hello @dilip2615 thanks for your proposed solution, although it doesn't solve the problem.
This should be addressed in higher level and patched within the WordPress core itself because it is an actual issue.
The do_blocks(...)
function removes the wpautop(...)
automatically but... it is added again in wp-includes/blocks/shortcode.php:19
One solution would be removing this wrapper from render_callback but I don't know the real impact of it!
Hello @arl1nd you can try this if this suggestion is helpful.
Create a Filter for widget_block_content:
Add this code to your theme's functions.php file or a custom plugin:
If this issue affects multiple shortcodes or needs a global solution, you can add a generalized filter:
This ensures wpautop won't interfere with any shortcode processed within widget blocks.
Let me know if you need further clarification or adjustments!