$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>editor - Enable Gutenberg on custom post type|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

editor - Enable Gutenberg on custom post type

matteradmin10PV0评论

I have this custom post type:

function create_posttype() {
  register_post_type( 'companies',
    array(
      'labels' => array(
        'name' => __( 'شرکتهای عضو' ),
        'singular_name' => __( 'شرکت' )
      ),
      'supports' => array('title', 'editor', 'custom-fields', 'excerpt', 'thumbnail'),
      'public' => true,
      'has_archive' => true,
      'rewrite' => array('slug' => 'companies'),
    )
  );
}
add_action( 'init', 'create_posttype' );

Which shows classic editor in WordPress admin area. I tried to replace 'editor' with 'gutenberg' in the supports array which doesn't work. I also added this code to my function as suggested here:

add_filter('gutenberg_can_edit_post_type', 'prefix_disable_gutenberg');
function prefix_disable_gutenberg($current_status, $post_type)
{
    if ($post_type === 'companies') return true;
    return $current_status;
}

How can I have a Gutenberg editor on my custom post type?

I have this custom post type:

function create_posttype() {
  register_post_type( 'companies',
    array(
      'labels' => array(
        'name' => __( 'شرکتهای عضو' ),
        'singular_name' => __( 'شرکت' )
      ),
      'supports' => array('title', 'editor', 'custom-fields', 'excerpt', 'thumbnail'),
      'public' => true,
      'has_archive' => true,
      'rewrite' => array('slug' => 'companies'),
    )
  );
}
add_action( 'init', 'create_posttype' );

Which shows classic editor in WordPress admin area. I tried to replace 'editor' with 'gutenberg' in the supports array which doesn't work. I also added this code to my function as suggested here:

add_filter('gutenberg_can_edit_post_type', 'prefix_disable_gutenberg');
function prefix_disable_gutenberg($current_status, $post_type)
{
    if ($post_type === 'companies') return true;
    return $current_status;
}

How can I have a Gutenberg editor on my custom post type?

Share Improve this question asked Dec 30, 2018 at 12:31 ehsanehsan 4531 gold badge4 silver badges8 bronze badges 1
  • this article may help you - webomnizz/… – jogesh_pi Commented Sep 7, 2020 at 7:26
Add a comment  | 

2 Answers 2

Reset to default 72

For Gutenberg to work in a Custom Post Type you need to enable both the editor in supports (which you already have) and show_in_rest. So add 'show_in_rest' => true, to your post registration arguments array.

Start by registering a Gutenberg WordPress custom type. The process is fairly easy and involves adding the following the code snippet.

/*Register WordPress  Gutenberg CPT */
function cw_post_type() {

    register_post_type( 'portfolio',
        // WordPress CPT Options Start
        array(
            'labels' => array(
                'name' => __( 'Portfolio' ),
                'singular_name' => __( 'Portfolio' )
            ),
            'has_archive' => true,
            'public' => true,
            'rewrite' => array('slug' => 'portfolio'),
            'show_in_rest' => true,
            'supports' => array('editor')
        )
    );
}

add_action( 'init', 'cw_post_type' );

add the show_in_rest key and set it to true via your custom post type.

'show_in_rest' => true,
   'supports' => array('editor')

As you can see, the above code snippet just set the ‘show_in_rest’ parameter to ‘TRUE’. After this step, when you create or edit a custom post type, you will see the Gutenberg editor visible and enabled.

All the steps and query discuss in detailed at https://www.cloudways/blog/gutenberg-wordpress-custom-post-type/

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far