• Skip to primary navigation
  • Skip to main content
OsomCode

OsomCode

Awesome code tutorials for WordPress and Genesis

  • Subscribe
  • My account
    • Edit profile
    • Favorites
    • Update credit card
  • Login

Enable block editor on a Custom Post Type by code

Learn in this tutorial how to enable the WordPress block editor on the Custom Post Types (CPTs) of your choice by code.

The block editor comes loaded with interesting and great features, but sometimes it doesn’t load on all post types.

Do you want WordPress block editor to be available in your favorite CPT?

You only need a few lines of code:

Snippet to enable WordPress block editor in a CPT

Two situations can arise:

  • That the CPT plugin was created by you.
  • Or that it is a plugin from WordPress repository.

Here is the solution for both possibilities.

1. With your own Custom Post Type Plugin

If you used the tutorial to create a CPT by code, you’re in luck. You don’t need to do anything because it’s already prepared to show the block editor.

If you have done it but it doesn’t show up, make sure the plugin has the following lines:

To see this and another 839 code snippets of this website, login or subscribe here.

If it meets these requirements you can edit the Custom Post Type with the block editor without problems.

2. With a CPT plugin created by another developer

If the plugin has been developed by a third party, add this fragment in functions.php:

To see this and another 839 code snippets of this website, login or subscribe here.

In this case the block editor would be available in the CPT “Course” (i.e. with the slug “course”). Of course, I invite you to change it to the one you are interested in.

As this last snippet is not specific to Genesis, you can use it for any child theme.

Conclusions

The block editor doesn’t display in any of your CPTs? Now you know how to selectively enable it by code.

If you want information on how to adapt the Genesis child themes to the WordPress block editor, check the tutorial with all the optimizations you need to maketo make sure it is compatible with it.

Any questions? Let me know in the comments.

And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉

Block Editor CPT PHP

To leave read and make questions about this code, you can login or register.

  • About OsomCode
  • FAQ
  • Contact

Legal Notice · Privacy Policy · Cookie Policy · Terms and conditions
Copyright © 2023

Lost your password?