While updating some of my older WordPress posts, I noticed that some of the code I’d used that worked with the older classic editor no longer works with Gutenberg. Even though I admitted my mistake and embraced Gutenberg, it’s annoying that the two filters I used no longer work. In this article, I’ll document three use cases.
1. “post_updated_messages” Filter
The first filter that I miss in Gutenberg is called “post_updated_messages”. In the classic editor, the WordPress system triggered this filter whenever a post was updated, and we could use it to change the message that appeared on the top of the editor. I found this filter most useful whenever I wanted to check the post’s content and, if necessary, revert the status based on some criteria.
For the first example, let’s say you want to include a minimum or maximum title length for your post writers. To ensure that they comply, I would use the “post_updated_messages” to check the length of the title, and if it was too long, I would unpublish the post with an error message on top.
As a second example, if you have a lot of guest writers, you want to ensure that they don’t link out too often. If you’re paranoid, you might worry that they’re accepting payment for linking to a 3rd party website. You could use the “post_updates_messages” notification to check the content for links to 3rd party domains, and then unpublish the post and mark it as pending when you can review it later.
With Gutenberg, actions like this are no longer possible.
2. “post_link” Filter No Longer Fires on the “Insert Link” Tool
We can use the “post_link” filter to change the URL returned by WordPress for a given post object. I used this filter to allow the “Insert Link” tool to return the “pretty permalinks” of even draft posts. This allowed me to create pages in advance, interlink them all, and then publish them all at once. Previously, linking to a draft post would only insert the “ugly” permalink used for previews.
Unfortunately, the “post_link” filter no longer fires when you insert a link using the Gutenberg editor in WordPress. I can’t link to draft posts with pretty permalinks anymore. It’s not too big of a loss in functionality, but for those who needed it, the loss hurts.
Filtering “admin_notices” Instead of “post_updated_messages”
As a poor workaround, the “admin_notices” filter can be used for some cases where you previously had the “post_updated_messages” filter. It’s far from perfect and doesn’t work at all while editing a post, so it’s useless to verify the content of a post. But at least you can still use it when you inform the user that they need to update a plugin or theme.
Keep Using the Classic Editor if you Need To
In the worst-case scenario, you can always install the WordPress classic editor plugin. Even though the WordPress team says they’ll maintain it only till 2024, there’s a good chance it’ll keep working for longer, as the community will keep updating it for compatibility. For how long? No idea. But in the near future, you can rely on it.
Despite the Loss, Gutenberg is a Huge Step Forward
Annoying as the loss of functionality is, I prefer Gutenberg to the classic editor. My pages are now more than just plain text and contain visual elements I could only dream of before. So I’m not complaining too hard!
I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!