Advertisement
salmancreation

Add support for Gutenberg

Feb 25th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 KB | None | 0 0
  1. GREAT Post -
  2. https://themeshaper.com/2018/02/15/styling-themes-for-gutenberg/
  3. https://themehybrid.com/weblog/align-wide-and-full-classes
  4.  
  5. /**
  6. * Add support for Gutenberg.
  7. *
  8. * @link https://wordpress.org/gutenberg/handbook/reference/theme-support/
  9. */
  10. add_theme_support( 'gutenberg', array(
  11.  
  12.     // Theme supports wide images, galleries and videos.
  13.     'wide-images' => true,
  14.  
  15.     // Make specific theme colors available in the editor.
  16.     'colors' => array(
  17.         '#ffffff',
  18.         '#000000',
  19.         '#cccccc',
  20.     ),
  21.  
  22. ) );
  23.  
  24.  
  25.  
  26.  
  27. @media (min-width: 750px) {
  28.  
  29.     .alignfull {
  30.         margin-left: calc(50% - 50vw);
  31.         margin-right: calc(50% - 50vw);
  32.         width: auto;
  33.         max-width: 1000%;
  34.     }
  35.  
  36.     .alignwide {
  37.         margin-left: calc(25% - 25vw);
  38.         margin-right: calc(25% - 25vw);
  39.         width: auto;
  40.         max-width: 1000%;
  41.     }
  42.  
  43. }
  44.  
  45. 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
  46.  
  47.  
  48. /**
  49. * Enqueue editor styles for Gutenberg
  50. */
  51.  
  52. function theme_slug_editor_styles() {
  53.     wp_enqueue_style( 'theme-slug-editor-style', get_template_directory_uri() . '/assets/stylesheets/editor-style.css' );
  54. }
  55. add_action( 'enqueue_block_editor_assets', 'theme_slug_editor_styles' );
  56.  
  57.  
  58. 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:
  59.  
  60. /**
  61. * Enqueue editor styles for Gutenberg
  62. */
  63.  
  64. function theme_slug_editor_styles() {
  65.     wp_enqueue_style( 'theme-slug-editor-style', get_template_directory_uri() . '/assets/stylesheets/editor-style.css' );
  66.     wp_enqueue_style( 'theme-slug-fonts', theme_slug_fonts_url(), array(), null );
  67. }
  68. add_action( 'enqueue_block_editor_assets', 'theme_slug_editor_styles' );
  69.  
  70.  
  71. 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