Full width images are a sweet new feature that Gutenberg offers to WordPress theme developers. In order to enable these in your theme, it takes just a few lines of code.
By default, the Gutenberg Image Block only has the three classic alignment options: left-aligned, centered, and right-aligned.
Enabling Wide Images in the Gutenberg Editor
First, a bit of PHP. Add this to your theme’s functions.php, or wherever else you are adding your
Now, you can find two new icons on your Image Gutenberg Block, wide-align, and full-width.
When one of these options is selected, it will display correctly in the editor. If you select wide-align, the image gets wider, and if you select full-width, the image fills the editor horizontally.
Wide Image Previews in the Gutenberg Editor
There’s just one issue: Although WordPress adds special classes to the image markup, this doesn’t affect your actual theme styles.
To solve this, add your own CSS. Here’s a snippet I came up with:
A few notes about the CSS:
calc()tells the browser to calculate a value (usually) based on the screen size.
vwrefers to “viewport width,” or screen width.
After the styles are applied:
So, with less than 20 lines of code, you can add this powerful and attractive feature to your themes.