Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active May 13, 2019 21:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/bf631e42a4b272b576c6175fdd75b330 to your computer and use it in GitHub Desktop.
Save billerickson/bf631e42a4b272b576c6175fdd75b330 to your computer and use it in GitHub Desktop.
<?php
/**
* Gutenberg layout class
* @see https://www.billerickson.net/change-gutenberg-content-width-to-match-layout/
*
* @param string $classes
* @return string
*/
function ea_gutenberg_layout_class( $classes ) {
$screen = get_current_screen();
if( ! $screen->is_block_editor() )
return $classes;
$layout = false;
$post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : false;
// Get post-specific layout
if( $post_id )
$layout = genesis_get_custom_field( '_genesis_layout', $post_id );
// Pages use full width as default, see below
if( empty( $layout ) && 'page' === get_post_type() )
$layout = 'full-width-content';
// If no post-specific layout, use site-wide default
elseif( empty( $layout ) )
$layout = genesis_get_option( 'site_layout' );
$classes .= ' ' . $layout . ' ';
return $classes;
}
add_filter( 'admin_body_class', 'ea_gutenberg_layout_class' );
/**
* Full width layout for pages as default
*
* @param string $layout
* @return string
*/
function ea_full_width_pages( $layout ) {
if( is_page() )
$layout = 'full-width-content';
return $layout;
}
add_filter( 'genesis_pre_get_option_site_layout', 'ea_full_width_pages' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment