Site logo

Archived topic

Content Container in block view

3 replies · Started by Dan on February 8, 2022

Viewing posts 1–4 of 4

Hi -

I have just made a new GeneratePress installation and activated the Elements feature. From there, I've created a new Layout Element. Within that Layout Element, I've set the Content Area to "fullwidth". This new Layout Element is also set to be used on all Pages.

Now, when I go to the backend of a page (I'm also using GenerateBlocks), my backend view is showing up as if it is "contained" instead of "fullwidth". I see that the Content Container on the page is set to "default" and is disabled. So, even though the corresponding Layout Element is set to "fullwidth", I still get a contained view on the backend when the Page setting (default) feels like it should be deferring to the Element setting (fullwidth).

To be clear, the front end is respecting this combination of settings, but the backend is not.

I've also played around with other combinations of the Element and Page settings and have found that the backend container is solely influenced by the setting on the Page. So, if I do the following, I can get a full-width backend.
1. Set the Element to "default".
2. Set the Page to "fullwidth".
3. Save and refresh the page backend.

But this feels unintended because I need to do this for every page instead of respecting the global Element setting. Please confirm if this behavior is intended, if I'm looking at this improperly, or if it is a bug.

Thanks for your time.

Hi Ying -

Thanks for your response.

Unfortunately, I'm still having trouble. The function that Tom has posted from that link was on my site and I did not see a change - even after resaving the Element and the Page in question just in case.

I'm selecting "Full Width (no padding)" as the option in the Element. That shouldn't need a content width set. In the workaround code that Tom supplied, he is just looking at the content width only after he enumerates through the Layout Elements. There should be an if-check to determine if "Full Width" is selected and if it is, add the appropriate classes to make the block editor fullwidth.

I've updated the function a bit in such a manner.


add_action( 'enqueue_block_editor_assets', function() {
	global $generate_elements;

	foreach ( $generate_elements as $element ) {
		if ( 'layout' === $element['type'] ) {
			
			//	Content area is expected to be 'full-width', 'contained', or '' (default).
			$content_area = get_post_meta( $element['id'], '_generate_content_area', true );
			
			//	If full width is preferred, then force the block editor to show full width.
			if ( $content_area == 'full-width' ) {
					$admin_css = 'body .wp-block{max-width: 100% !important; }';
					wp_add_inline_style( 'generate-block-editor-styles', $admin_css );
			}
			
			//	If 'contained' is preferred, then look at the content width.
			else if ( $content_area == 'contained' ) {
				$content_width = get_post_meta( $element['id'], '_generate_content_width', true );

				if ( $content_width ) {
					$admin_css = 'body .wp-block{max-width: ' . absint( $content_width ) . 'px !important;}';
					wp_add_inline_style( 'generate-block-editor-styles', $admin_css );
				}				
			}
		}
	}
}, 100 );

With minor testing, this appears to work for me. If you concur that this is more correct, please include it in the next release. Otherwise, please correct what I may be doing improperly.

Thanks for the effort.

Thanks for sharing :)

The GP theme 3.1.3 has been released today, GP premium 2.1.2 will be released in the next couple of days.

After updating both the theme and the plugin, this issue should be fixed.

Let me know if you find any more bugs with the new releases.

Thanks!

This archived topic is closed to new replies.