-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
content_width and new block widths #5650
Comments
It's worth noting that it's a requirement to use |
Quoting from #5217 (comment) Quick note: Please be aware of the theme variable $content_width has been discussed a few times in core and it's seen as something "legacy", as it doesn't make much sense in a responsive era. It still make sense just for embeds, maybe. Some references: |
The question still stands as embeds can be wide and full-bleed. My testing of the demo post shows these blocks do not scale properly. |
My comment was meant to second your point:
|
Is there a filter inside Gutenberg blocks so I can temporarily change the |
So, what's the best way to fix this? :) The content width (actually That can actually be done on the front-end right now, with only one var. The content max-width is needed after the template is loaded, when outputting the HTML. The theme "knows" the max-width by that point and can set Of course it's not going to be that easy inside the editor. The solution there seems to be to set "default max-widths" for several common contexts. Then everything requiring a width inside the editor can be fluid (percent based) and the width can be decided by a "display filter" on the front-end, the same way How to do this:
|
Being able set multiple widths such as |
For the editor, definitely. For the front-end that's not going to work "perfectly", but probably well enough. Ideally the widths will be contextual there. We can still have It would be good to define defaults for these values:
In that terms the front-end will still work relatively well by setting only |
BTW, this needs to be set to continue with #6177. We are at a point where we need these values for the front-end code. |
When I reviewed this issue, my mind went to the Customization focus and block-based page layouts. I could be off here due to low WP experience, but it seems like the approach we choose should be flexible enough to express different widths for different parts of a page layout (e.g., header, footer, content, sidebar). I'm not suggesting we need to handle that now, just mentioning in case it affects our solution in the near term. |
Exactly, that's what I was thinking too. More thoughts: #6177 (comment) I also think that |
What makes this even more difficult is the fact that in a responsive era not everything is defined in pixels. Many themes use things like |
It seems to me that the place to define content widths (and their use by both the editor and PHP) is in the theme and/or template header blocks. Those definitions should allow the values to be any "legal" CSS value, as mentioned above: /*
Template Name: My Fancy Template
Content Width: 100%
Full Width: 100vw
Wide Width: calc(100% + 40rem)
*/ Template values would override the same values set in the theme header, but the theme values would be used when a template doesn't specifically override them. Wordpress would itself have a set of default values used when the theme provides no context. This should allow WP to automatically adjust Without disappearing down a rabbit-hole, Gutenberg could opt to define the content column where the editor lives as (arbitrary value warning) 70% of the available horizontal space (allowing for the difference between wide [say 80%] and full [100%] to be shown when a template isn't yet chosen or the template lacks size information), but to use the defined values when available. Reviewing the documentation, the editor does not seem to have a method or methods to pass in environment information from the theme or template? Trying to style the Gutenberg editor to be template-contextual does not even seem possible with CSS at the moment. Inspecting a page being edited shows no "template" class in the admin HTML (ie, (As an aside, my clients--almost to an organization--view "pages" as the meat of their site, and any blog-style activities as a sideline. Page templates often have quite different presentation for the "same" HTML elements. One of the hardest things to explain to clients has always been "well, the visual editor sort of lays things out visually, but not really"...being able to use CSS to easily style the editor, based on environment, would go a long way to making Gutenberg a huge step up.) |
This isn't really a problem; you said it yourself : "The content_width global defines the max-width of content". |
@joyously The main problem outlined here is specifically about how we handle widths on the front end. |
Yes, and it doesn't seem like it is a problem, because the content_width is the max width of the content area. The theme should know what that is on any page, regardless of whether there is an element or two that are wanting to be full width. By defining it, the elements that depend on it can then be styled correctly (or not, because it really shouldn't play into any styles since it's for embeds mostly). |
As described in #9534 we need a much more ergonomic mechanism for handling different widths across different layouts and nested contexts. However, I think we could use |
I think this also relates to #9302, which is pulling in a hard-coded 580px max-width for images, even if CSS has defined a larger container width. |
As I mentioned above this is needed for #6177. It is implemented as a PHP global in #11377 (mostly to test) but thinking we can do better. This should probably be a filter and have a helper function that runs it and normalizes the values? The proposed format is an array with three values: $block_width = array(
'default' => 640,
'wide' => 800,
'full' => 1024,
); where That array can be (should be?) set contextually for each block container. For example: in the main content column the I know theme authors would love to be able to set these widths in vw but unfortunately that's not practical (for now). These values act mostly "max-width", and the |
Locked with #11973. |
Also the content width from theme has to be used by other blocks, notably columns block to adjust the media queries. |
Any news? |
The current idea is to move these to the |
This is now addressed with the new layout config in theme.json and container groups. |
The recently added Gutenberg Block Context API can be useful for this: E.g. a |
Issue Overview
Most themes ship with the
content_width
global which controls among other things the width of embedded content. With the ability to change the width of any piece of content beyond what is normally considered the content width, a new best-practice has to be established, or more likely thecontent_width
global has to be reevaluated for this new reality.Steps to Reproduce (for bugs)
content_width
global for a theme.Expected Behavior
The
content_width
global defines the max-width of content displayed in any specified scenario.Current Behavior
Because of the new widths enabled by Gutenberg, it is hard to figure out what width to target: If the 'regular' content width is chosen, embedded items are too small if they are displayed as wide or full. If full-bleed is chosen, embedded contents are too wide and have to be scaled down by the CSS which is not great.
Possible Solution
Solve the long-running
content_width
riddle in the context of Gutenberg by rethinking the approach from the ground up: What elements are affected bycontent_width
, how can the global take into account responsive / fluid widths that don't use hard pixel values, and does thecontent_width
global have a role at all in the Brave New World of WordPress Blocks?Related Issues and/or PRs
#1483
The text was updated successfully, but these errors were encountered: