Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GREAT Post -
- https://themeshaper.com/2018/02/15/styling-themes-for-gutenberg/
- https://themehybrid.com/weblog/align-wide-and-full-classes
- /**
- * Add support for Gutenberg.
- *
- * @link https://wordpress.org/gutenberg/handbook/reference/theme-support/
- */
- add_theme_support( 'gutenberg', array(
- // Theme supports wide images, galleries and videos.
- 'wide-images' => true,
- // Make specific theme colors available in the editor.
- 'colors' => array(
- '#ffffff',
- '#000000',
- '#cccccc',
- ),
- ) );
- @media (min-width: 750px) {
- .alignfull {
- margin-left: calc(50% - 50vw);
- margin-right: calc(50% - 50vw);
- width: auto;
- max-width: 1000%;
- }
- .alignwide {
- margin-left: calc(25% - 25vw);
- margin-right: calc(25% - 25vw);
- width: auto;
- max-width: 1000%;
- }
- }
- This approach works, but because vw includes the width of the vertical scrollbar as part of the whole screen width, you can get a little horizontal scrolling. One fix is adding overflow: hidden to one of the page-width elements further up the
- /**
- * Enqueue editor styles for Gutenberg
- */
- function theme_slug_editor_styles() {
- wp_enqueue_style( 'theme-slug-editor-style', get_template_directory_uri() . '/assets/stylesheets/editor-style.css' );
- }
- add_action( 'enqueue_block_editor_assets', 'theme_slug_editor_styles' );
- Like with the TinyMCE editor, you can also include fonts. So for example, if your theme is enqueuing fonts from Google, you can include them in the Gutenberg editor, too:
- /**
- * Enqueue editor styles for Gutenberg
- */
- function theme_slug_editor_styles() {
- wp_enqueue_style( 'theme-slug-editor-style', get_template_directory_uri() . '/assets/stylesheets/editor-style.css' );
- wp_enqueue_style( 'theme-slug-fonts', theme_slug_fonts_url(), array(), null );
- }
- add_action( 'enqueue_block_editor_assets', 'theme_slug_editor_styles' );
- The editor styles need to be pretty specific to make sure they’re not applied to other elements of the page outside of the editor — Rich Tabor has a good post here about his experience with this behavior. Gutenberg includes specific classes around different elements in the editor, so you can prefix selectors more generally with the class .editor-post-visual-editor, or use more specific classes to target individual blocks — for example, styles for .editor-block-list__block[data-type="core/heading"] h1 would only be applied to h1s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement