Okay let’s be honest, friends. Not everything is ready for Gutenberg. In fact, I myself have certain sites that aren’t ready for it today. That’s why there exists an excellent plugin known as the Classic Editor. This allows you to decide it you want to block Gutenberg (which is the default option) or if you want to allow users to chose between Gutenberg and Classic editors.
But what if you want to go a step further?
What if you want to have Gutenberg on by default for posts and pages, but not for a custom post type?
Don’t worry. We can do that.
The Code
The basic idea is that if WP is 5.0 or higher, make sure that the Classic Editor is installed. If it’s less than 5.0, make sure Gutenberg is installed. Then block the code as needed:
class HELF_Gutenberg {
public $gutenfree = array();
public function __construct() {
$this->gutenfree = array( 'post_type_ONE', 'post_type_TWO', 'post_type_THREE' );
add_action( 'current_screen', array( $this, 'gutenberg_removal' ) );
}
public function gutenberg_removal() {
// WP 5.0+ requires Classic Editor
// WP 4.9- requires Gutenberg
if ( ( version_compare( get_bloginfo( 'version' ), 5.0, '<=' ) && ! is_plugin_active( 'gutenberg/gutenberg.php' ) ) || ( version_compare( get_bloginfo( 'version' ), 5.0, '=>' ) && ! is_plugin_active( 'classic-editor/classic-editor.php' ) ) ) {
return;
}
// Intercept Post Type
$current_screen = get_current_screen();
$current_post_type = $current_screen->post_type;
// If this is one of our custom post types, we don't gutenize
if ( in_array( $current_post_type, $this->gutenfree, true ) ) {
remove_filter( 'replace_editor', 'gutenberg_init' );
remove_action( 'load-post.php', 'gutenberg_intercept_edit_post' );
remove_action( 'load-post-new.php', 'gutenberg_intercept_post_new' );
remove_action( 'admin_init', 'gutenberg_add_edit_link_filters' );
remove_filter( 'admin_url', 'gutenberg_modify_add_new_button_url' );
remove_action( 'admin_print_scripts-edit.php', 'gutenberg_replace_default_add_new_button' );
remove_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' );
remove_filter( 'screen_options_show_screen', '__return_false' );
}
}
}
new HELF_Gutenberg();
One of the other cool things you can do is to have an embed like [ embed height="400" width="600"]...[/embed ] to embed a video:
Yes, you could just paste in the video URL, but this is a demonstration of a shortcode as a sort of block. And speaking of blocks…
Blocks Tomorrow
In Gutenberg (which this post was written with), you can keep using in-line shortcodes and even add a shortcode as a block:
To a degree, that works well. But there are other options with Gutenberg.
Sidebar Edits
First, you can see this in a normal paragraph block. Adding options to the sidebar:
This allows you to edit the various options on the right sidebar and, thus, change the customizable aspects of the block. For many shortcodes, you can keep that interface and have everything be perfectly functional. Have a block that shows user information? Put a dropdown for the users on the sidebar, and so on.
Inline Edits
The other options is an integrated block. For example, here’s my example of a review block, with text fields and dropdowns to allow you to edit in situ.
In my opinion, this is a more fluid interface, as you can see example what you’re doing and what it’s going to look like.
How Will You Use The Future?
There are still hurdles to overcome with Gutenberg, but as we step forward, we’re getting a better look at an integrated editor that gives you a lot of that desired ‘What you see is what you get’ experience.
While I did write up Spoiler Blocks for Gutenberg one way, I also sat down recently and rewrote it a little cleaner. The primary difference here is how I’m properly using defaults:
No, this isn’t something snazzy about doing cool things with categories within Gutenberg (although you could). This is about making a section for your own blocks. A category.
What’s a Category?
I’m incredibly lazy, so when I use blocks, I type /head and make sure I get the right block, hit enter, and keep on typing.
But. Sometimes I think I need a specific block and I don’t know the name, so I click on the circle + sign and I get a list of categories!
You won’t see reusable if you didn’t make some, but the point is that you could make a custom category for your custom blocks.
Making a straight forward block to insert content in Gutenberg is (relatively) easy. I hate using the word ‘easy’ here, because in order to do it you will need to master a whole new world of coding, but all things considered, yes. It is easy. In fact, Gary (aka Pento) wrote a sample plugin that will let you convert a shortcode to a Gutenberg Block.
I myself have written a mildly complicated Spoiler Block (there’s a new version of it I will share soon). But then the day happened that my cohort in lesbian TV crime, Tracy, expressed annoyance at how Gutenberg destroyed her listicle.
What is a Listicle?
Have you seen those posts that show you the top ten ways to LifeHack your used egg cartons? Those are listicles. They’re lists (list) articles (icle). Makes sense, right? Listicles have a pretty basic format as well, there will be a header with some sort of numerical mark, then content with images etc. This repeats for the number of times you have an article.
Most people make them by hand by manually editing the numbers in their header. That’s all well and good until you want to craft better formatting and have a listicle look somehow ‘different’ from the rest of your content. Maybe you want them to have a special background color, or a different design for the header.
If we were doing this in the old, simple, HTML way, it would look like this:
What this does is create a CSS counter and increment it every time you use <dt> creating an auto incrementing list.
No HTML for Gutenberg
Now, if you know the HTML, you can still do this in Gutenberg in HTML by using the HTML block.
Example of summoning the Custom HTML block.
But if you don’t know HTML, then this is a bloody nightmare to handle. And part of the reason why I’m very pro-Gutenberg is that it’s 2018, and expecting people to know all the myriad magical steps of HTML, in order to create a webpage, feels passé. No, it feels restrictive. We can’t expect websites to advance and become more than just pages if we don’t give them the tools.
Complex Design
Unlike the relatively simple javascript I used to make my Spoiler Box block, to do this requires the use of a feature called ‘Inner Blocks‘ which is effectively putting a block inside a block.
My original idea was to have a multiple nested block with the following:
Listicle Block that calls a template of a list item
ListItem block that calls a title and description
ListDT block that calls the title
ListDD block that allows you to add whatever more inner blocks you want
It sounds incredibly complicated, and sadly the perfect version was so difficult I actually started with a pared down version.
Listicle block that sets up a template of title and description
The problem here is that I end up having a separate dl for each block. I can work around it with some CSS magic, but it’s not perfect. So I knuckled down and actually wrote the code that does exactly what I want. Whew.
Some Code
… Actually I’m going to do something I hate and that’s link to an external directory.
I’ve build out Listicles for Gutenberg for you to peruse and fork and enjoy. Or even use if you want, becuase it does work. But it’s big. No, it’s huge for an in-post example. And to explain everything line by line wouldn’t help.
If you go to the repository, the Gutenberg source code is located in /src/ – that’s where most (if not all) of your work will happen.
blocks.js – A list of all the separate JS files included
/block/listicle.js – The main listicle file
/block/listitem.js – Individual list items (this is only usable inside the Listicles block)
/block/listdt.js – The list title
/block/listdd.js – The list content (this allows you to add as many sub blocks as you can)
And yes, not only does it auto increment as you move the slider (or bump the counter), you can flip it into reverse mode:
The real trick of it all was the copious use of templates.
It’s all Complicated
Besides the fact that the blocks aren’t quite where I want them to be, I also have to use a block builder to convert that javascript into my real files. I chose the Create Guten Block builder, instead of building out my own NPM build script.
That too illustrates some of the concerns people have, and rightly so, about blocks being incredibly more complicated than they need to be. And yet, having gone through the exercise myself, I think that it’s perhaps not going to be that much of a drama.
For those of use who generally just make new shortcodes, the world won’t change too much. Gutenberg supports inline shortcodes, after all, which is the majority of what people need from it. We want to be able to make our own embed blocks, which again isn’t terrible, and when someone gets to the complicated point of needing something advanced like a listicle, well eventually there will be a plugin that will handle this better than a shortcode.
By now I’m sure most of you have seen Gutenberg. And I’m sure you all have a lot of opinions about Gutenberg and why it’s absolutely not needed. You may also have read conversation about how we totally need Gutenberg, and it’s part of the long view of the future.
I’m going to tell you something that may be difficult to accept.
We need Gutenberg because post editing is broken.
The Visual Editor is Limited
The current visual editor, which uses TinyMCE, is incredibly limited. It’s awesome, as you can make a WYSIMWYG (What you see is mostly what you get) post, but it can be really hard to get layout and design flow to look ‘right.’ And if you want to insert custom content, you’re left using embeds or shortcodes.
I love shortcodes. But. They’re weird and complicated and no two work exactly the same way. People don’t always document them, they’re not discoverable, and they can be incredibly obscure to use. Which ones take input and which are nested and so on.
This means that advanced customization of post content is left to templating engines in those page-builder plugins, which either have to re-jigger the whole screen (like Gutenberg) or utilize a complex nesting of shortcodes (like that other plugin you’re thinking about). Neither is a great experience for users, especially when no two page builders work the same way.
The HTML Editor is Cryptic
If you’re not a developer or someone who read the original HTML 2.0 spec book (hardcover, y’all), then HTML may be a beast you don’t understand. It’s complicated, it has a lot of weird quirks, and you’ll hear people tell you to use tables (or not), or use divs (or not), or only troglodytes use spans and colors.
Basically it’s confusing unless you know HTML, and that means if you’re not an advanced user or a designer/developer, you’re screwed. You’re expected to learn a whole new suite of complex arcana just to make a table with today’s WordPress. Or you use a plugin and then you find out the semantic HTML it used was problematic, and you have no idea how to fix it.
Anyone who supports end-users who know MS Word and not WordPress have dealt with this drama. It’s real, and WordPress is still struggling to address it. Which is why we have Gutenberg in the pipeline.
Gutenberg Isn’t Perfect
None of this is to say that Gutenberg is perfect. I’ve had experiences with exactly how hard it is to wrangle. Building new blocks is crazy hard if you’re not using simple reusable blocks like my favourite spoiler block:
If you want to make a complicated nested block it’s frustrating. You have to decide what flavour of Javascript you want to use and how to build it. Let’s be honest here, folks, it’s tough to be a developer in this new land.
And as a user it’s no picnic either. It’s a lot of change and kicking yourself out of old habits and into embracing the new. Which we’re all generally terrible at. You have to shift from a fundamental concept of “Big Chunk of Content” and into “Smaller Blocks of Content.” Meta boxes and data like we add with ACF and CMB2 isn’t perfect yet either. Heck, I can’t even customize my Jetpack sharing with Gutenberg yet.
But. As we use Gutenberg and as we inch forward, we start to see the progress. I can still insert tables via HTML inside a Gutenberg post. I can build (or hire someone to have built) a block to tweak things to my heart’s content. Things may be hard, but they’re possible.
You Must Break a Bone to Set It
When I was 11, I broke my arm. And I remember the feeling of abject horror when the doctor told me they’d have to break my arm again in order to set it. I used some language they’d never heard from a child my age. And it hurt like hell. It was the most pain I’d been in my young life.
My arm never worked the ‘same’ way afterwards either. Oh sure, I could do pretty much everything, but I had to compensate and learn new ways to do other things. I don’t have full rotation in my wrist still, though it’s much better, which meant I had to change how I did certain motions. Like typing, that hand rarely rests on the keyboard. In short, I had to adapt.
The current editor is imperfect and broken. In order to fix it, we must shatter it and move forward. It hurts, it’s a struggle, but if we push each other, we can do this. Continue to criticize the things that are missing (not being able to hide taxonomies from use, for example), but do so in a way to help it forward.
Cookie Consent
We use cookies to improve your experience on our site. By using our site, you consent to cookies.
Contains information related to marketing campaigns of the user. These are shared with Google AdWords / Google Ads when the Google Ads and Google Analytics accounts are linked together.
90 days
__utmx
Used to determine whether a user is included in an A / B or Multivariate test.
18 months
_gali
Used by Google Analytics to determine which links on a page are being clicked
30 seconds
_ga_
ID used to identify users
2 years
_ga
Used to distinguish users.
2 years
_gat
Used to throttle request rate.
1 minute
_gid
Used to distinguish users.
24 hours
__utma
Used to distinguish users.
Persistent
__utmb
Used to determine new sessions/visits.
30 minutes
__utmc
Used to determine if the user is in a new session/visit.
Session
__utmt
Used to throttle request rate.
10 minutes
__utmv
Used to store visitor-level custom variable data.
2 years
__utmz
Stores the traffic source or campaign that explains how the user reached your site.