-
-
Save billerickson/bf631e42a4b272b576c6175fdd75b330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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