Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.wp-site-blocks template HTML wrapper should be filterable #33798

Closed
jeremyfelt opened this issue Jul 31, 2021 · 4 comments
Closed

.wp-site-blocks template HTML wrapper should be filterable #33798

jeremyfelt opened this issue Jul 31, 2021 · 4 comments
Labels
[Type] Enhancement A suggestion for improvement.

Comments

@jeremyfelt
Copy link
Member

What problem does this address?

get_the_block_template_html() in WordPress and gutenberg_get_the_template_html() in Gutenberg build the template HTML for the current page view and then wrap it in <div class="wp-site-blocks"> immediately before returning. This is a decision made in the original implementation, #17626.

What is your proposed solution?

It should be possible for a theme and the user to have as much control over the markup as possible. This wrapper may work as a default for many themes, but is not strictly necessary.

I would propose adding a filter here, maybe like so:

$original_content = $content;
$content = '<div class="wp-site-blocks">' . $content . '</div>';
$content = apply_filters( 'gutenberg_get_the_template_html', $content, $original_content );

It could also be more complex and filter both whether the content should be wrapped and then what the wrapping class is.

This would have an impact on how the automatic skip-link JS is generated, though that can easily be replaced by a theme via the wp_footer action.

@sparklingrobots sparklingrobots added [Block] HTML Affects the the HTML Block [Block] Template Part Affects the Template Parts Block [Type] Enhancement A suggestion for improvement. labels Aug 10, 2021
@ngdangtu-vn
Copy link

Thanks, I really need this fix. Do you know why we still don't it? Is there anything I can do?

@carolinan
Copy link
Contributor

wp-site-blocks is used for the output of alignments, margin, block gap, and the root padding from theme.json.

@carolinan carolinan removed [Block] HTML Affects the the HTML Block [Block] Template Part Affects the Template Parts Block labels Mar 27, 2023
@fabiankaegy
Copy link
Member

I'm currently into an issue which would also require the ability to filter the markup of templates before they are rendered.

I have a custom rich text format which stores some data as data-attributes. This rich text format should pull in dynamic data and for regular posts and pages we can accomplish this using the HTML_Tag_Processor and a filter on the_content filter. However this doesn't work for the templates.

(My case it kind of related to this issue here: #18490 )

@jeremyfelt
Copy link
Member Author

I think this ship probably sailed 2 years ago. 😅

FWIW, I'd be okay closing this request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
5 participants