Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active May 7, 2019 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/ca40ce486ce3512b0c1ce90840c232c8 to your computer and use it in GitHub Desktop.
Save billerickson/ca40ce486ce3512b0c1ce90840c232c8 to your computer and use it in GitHub Desktop.
wp.domReady(function () {
yourTheme.updateLayoutClass();
var layouts = document.querySelector(".genesis-layout-selector");
if( null === layouts )
return;
layouts.addEventListener("input", function (e) {
yourTheme.updateLayoutClass();
});
});
var yourTheme = {
getLayout: function () {
var inputs = document.querySelectorAll(".genesis-layout-selector input");
var layout = "";
for (var i = 0, len = inputs.length; i < len; i++) {
if (inputs[i].checked) {
layout = inputs[i].getAttribute("id");
break;
}
}
if (layout === "default-layout") layout = yourThemeConfig.defaultLayout;
return layout;
},
setWrapperClass: function (layout) {
var root = document.querySelector("body");
var classes = root.classList;
classes.forEach(function(c){
if (c.includes("genesis-")) root.classList.remove(c);
});
root.classList.add("genesis-" + layout);
},
updateLayoutClass: function() {
var layout = yourTheme.getLayout();
yourTheme.setWrapperClass(layout);
}
};
<?php
/**
* Gutenberg scripts and styles
*
*/
function ea_gutenberg_scripts() {
wp_enqueue_style( 'ea-genesis-layout', get_stylesheet_directory_uri() . '/assets/css/genesis-layout.css' );
wp_enqueue_script( 'ea-editor', get_stylesheet_directory_uri() . '/assets/js/editor.js', array( 'wp-blocks', 'wp-dom' ), filemtime( get_stylesheet_directory() . '/assets/js/editor.js' ), true );
$post_id = isset( $_GET['post'] ) ? intval( $_GET['post'] ) : false;
$post_type = isset( $_GET['post_type'] ) ? esc_attr( $_GET['post_type'] ) : false;
$default_layout = ( !empty( $post_id ) && 'page' === get_post_type( $post_id ) ) || ( !empty( $post_type ) && 'page' === $post_type ) ? 'full-width-content' : genesis_get_default_layout();
wp_localize_script( 'ea-editor', 'yourThemeConfig', array(
'defaultLayout' => $default_layout,
));
}
add_action( 'enqueue_block_editor_assets', 'ea_gutenberg_scripts' );
.genesis-content-sidebar .editor-styles-wrapper .wp-block,
.genesis-sidebar-content .editor-styles-wrapper .wp-block {
max-width: 640px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment