1

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.

0
1

I 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.