But then I asked myself something important. And you should ask yourself this, before you lament about how much work you have ahead.
Do I need a new block?
What’s a Block Anyway?
The concept of ‘block’ writing is one people who use Scrivner may be familiar with. Or maybe if you’ve ever been a part of a writer’s room, breaking down a season of a TV show. The idea is that each index card is it’s own entity.’ Or rather, in the case of WordPress, each paragraph is it’s own entity.
This means you can move the paragraphs around, which for paragraphs makes little sense. But for layout? Oh it makes a great deal more sense. A block is, literally, a block you move around until your page looks the way you want it to. Awesome.
Why Don’t We Need Them?
Actually the question should be when don’t we need them? Obviously we need blocks. That won’t change. But by default WordPress has quite a number of blocks out of the … block. And that begs the question of when and why do we need to make new ones?
This is a question many developers who have shortcode plugins will be asking themselves, and the realization I stumbled across at WordCamp San Diego is that … a lot of developers don’t need to make new blocks! Because a lot of shortcodes aren’t actually going to be all that necessary in the future.
Let’s use an example of something common…
Example Shortcode: Spoilers
Let’s say you have a WordPress site and it sometimes talks about spoilers.
Today in WordPress an easy way to put a warning at the top of every page would be with a shortcode that looks like
[spoilers] or if you’re feeling puckish,
[spoilers warning="OMG SPIDERS!!!"]
Those would output a simple paragraph that warned people about spoilers.
Right away, I thought “Oh, that would be a nice, easy sort of thing to turn into a block.” It’s just a direct output of some code:
<div class="alert alert-danger" role="alert"><strong>' . $warning . '</strong></div>
But then I thought …. What if I don’t?
Enter Shared Blocks
Shared Blocks, formerly called reusable blocks, are blocks of content defined by each site, specific to the site, that are .. well .. reusable. You don’t need to know how to code to make them, either. Which means you don’t need a developer to do this. Start by just making a new block with the content:
Warning: This post contains spoilers!
That’s easy. But what we want is to apply color to it. And that can be done in a number of ways. The easiest would be to use the advanced section in the block editor and add an additional CSS Class of, in this case, alerts.
But that isn’t the only way…. Because I can also make this:
Whaaat? Total game changer!
Gutenberg Blocks Are Editable
In every single Gutenberg block you can change text and color to suit your needs. I edited that particular block and said I wanted the background to be one color, the next another, and I wanted the size to be Large. I’m aware the large size doesn’t show properly… I also told it how I wanted the block alightment to look:
Okay, But Reusing?
Don’t worry, I didn’t forget. When you hover over a block there are three vertical icons on the right indicating a menu. Click on the menu and you get options and one is to convert it to a shared block. Click on that, give it the name you want, and you’ve created a block!
And now, when you go to enter a new block, you click on the plus button on the left, click on ‘Shared,’ and you have this:
Right away you’ll notice you can’t edit the shared block without editing it for everyone. So if you made it “Aaaaaahhh! Spiders!!!!!” everything would change. And that’s not great for everyone. But for a lot of people who just want a simple, repeatable, notice or signature, this is just fine.
It won’t spare you having to convert some of your shortcodes to blocks, but it may make life easier for people who don’t want to have to use them in the first place. And that, I think, is a win.