admin管理员组文章数量:1125942
I have a custom post type with a custom block to collect required data and store it in post meta data or standard fields like title or slug, so I don't want to display the Title block. I can't disable title support in the CPT, because too much else depends on it.
The only successful attempt so far has been using CSS to target the id "post-title-0" of the for the title and can clearly enqueue a small CSS file depending on the post type, but I don't want to depend on something set by Wordpress that I can't control; it feels that something in Javascript would be a better way to go if possible. I was wondering if WP provde any hooks for this but haven't found any.
I'm a javascript novice, having started learning it in the last few weeks in order to write some custom blocks, so am not clear on the extent of what can be acheived with it. (I have 50 years experience of programming, just not in JS).
It would be OK to only hide the title until the post has been saved.
I did see one relevant post on here but it was for the Gutenberg plug-in and I didn't know if I could adapt it for current versions.
Has anyone any ideas?
** Since there seems to be no JS option, my final solution was to hook into the admin_body_class filter to add a class with the post type name, then an entry in CSS to target and hide the title for specific custom post types.
I have a custom post type with a custom block to collect required data and store it in post meta data or standard fields like title or slug, so I don't want to display the Title block. I can't disable title support in the CPT, because too much else depends on it.
The only successful attempt so far has been using CSS to target the id "post-title-0" of the for the title and can clearly enqueue a small CSS file depending on the post type, but I don't want to depend on something set by Wordpress that I can't control; it feels that something in Javascript would be a better way to go if possible. I was wondering if WP provde any hooks for this but haven't found any.
I'm a javascript novice, having started learning it in the last few weeks in order to write some custom blocks, so am not clear on the extent of what can be acheived with it. (I have 50 years experience of programming, just not in JS).
It would be OK to only hide the title until the post has been saved.
I did see one relevant post on here but it was for the Gutenberg plug-in and I didn't know if I could adapt it for current versions.
Has anyone any ideas?
** Since there seems to be no JS option, my final solution was to hook into the admin_body_class filter to add a class with the post type name, then an entry in CSS to target and hide the title for specific custom post types.
Share Improve this question edited Mar 2, 2021 at 15:17 Jeremy Skelton asked Feb 28, 2021 at 16:54 Jeremy SkeltonJeremy Skelton 256 bronze badges 02 Answers
Reset to default 1I initially didn't believe this is possible officially at the moment, the post title is always included:
https://github.com/WordPress/gutenberg/blob/a6a0d3d47d24b83a58db7130fa82133428067326/packages/edit-post/src/components/visual-editor/index.js#L77
<div className="edit-post-visual-editor__post-title-wrapper">
<PostTitle />
</div>
The only exception at the moment is if a block template is being edited. In particular, this isn't a block. There is a post title block but it's only used in full site editing, not posts.
However, looking at the PostTitle
component, it wraps its internal components in a check:
<PostTypeSupportCheck supportKeys="title">
So the reason your post has a title box, is because your post type supports titles.
Assuming you have setup a custom post-type, as state above, to hide the title bar is incredibly simple. In your arguments ($arg) setup for register_post_type( 'YOUR_CUSTOM_POST', $args ); change the
'supports' => array( 'title' )
to
'supports' => array( 'revisions' ),
The register_post_type( 'YOUR_CUSTOM_POST', $args ), takes arguements under support as follows: array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
$args = array(
'register_meta_box_cb' => 'YOUR_CUSTOM_POST_meta_box',
'labels' => $labels,
'description' => 'Description of Post data',
'public' => false,
'menu_position' => 5,
'show_ui' => true,
//'supports' => array( 'title' ), // Turns on the title box
'supports' => array( 'revisions' ), <===== HERE
'has_archive' => false,
'menu_icon' => 'dashicons-list-view',
'delete_with_user' => false,
);
register_post_type( 'YOUR_CUSTOM_POST', $args );
本文标签: Disable title block on edit screen for a custom post type
版权声明:本文标题:Disable title block on edit screen for a custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736677892a1947277.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论