Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use block templates when there is no post_content #18517

Closed
stmarytx opened this issue Nov 14, 2019 · 3 comments
Closed

Use block templates when there is no post_content #18517

stmarytx opened this issue Nov 14, 2019 · 3 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Templates API Related to API powering block template functionality in the Site Editor Needs Technical Feedback Needs testing from a developer perspective. [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@stmarytx
Copy link

Use case: updating sites that have previously relied on postmeta for content - such as sites using ACF or page builders, where the main content is not stored in post_content.

Feature suggestion: I really wish Block Templates that are applied to post types would apply for not just new posts, but any post that does not currently contain any post_content.

I am converting several large sites over from using ACF in the past, where we heavily structured content and in many cases there is no post_content at all because it was all templated, over to the Block Editor instead. It is a tedious process that would be much faster if the Block Templates I have defined, which work beautifully for new posts, would also work for existing posts - but the templates aren't applied, I just get a completely blank "Start writing" screen.

The alternative I have is to delete my current posts and build new ones. What I don't like about that approach is, my sites have shortened permalinks, and it's not currently possible to set a permalink before you publish. It's hard to remember to update the permalinks in addition to all of the content, so I run the risk of a lot of 404 errors using this route. It also makes the content appear as though it was created whatever day I publish the new Block Editor version - it doesn't keep the historical published and updated dates, which are valuable for content auditing.

@ellatrix
Copy link
Member

Hi! You could use the default_content filter in PHP to define some default content for new posts. See https://developer.wordpress.org/reference/hooks/default_content/. For example, you could set it to

<!-- wp:image -->
<figure class="wp-block-image"><img alt=""/></figure>
<!-- /wp:image -->

to start with an image placeholder. I agree that there should be an easier way to do this though. It would be nice if it's possible to use a block template to define default content.

@ellatrix ellatrix added [Feature] Block API API that allows to express the block paradigm. [Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Help Request Help with setup, implementation, or "How do I?" questions. Needs Technical Feedback Needs testing from a developer perspective. labels Nov 20, 2019
@stmarytx
Copy link
Author

stmarytx commented Nov 20, 2019

Thanks for the reply, but that's not what I'm asking. New posts are already covered. My suggestion is, use the block template to add blocks not just to new posts, but also to existing posts when there is no post_content at all and someone is entering the editor.

Currently when a block template is defined for a CPT, those blocks in the template are added to new posts when entering the editor. I'm asking for that same functionality for existing posts when entering the editor - only when post_content is completely empty.

@talldan
Copy link
Contributor

talldan commented Apr 23, 2020

I think this is probably covered by the Block Patterns feature now in that the template can be made into a pattern as well that's easily insertable:
https://developer.wordpress.org/block-editor/developers/block-api/block-patterns/

I'll close this issue.

@talldan talldan closed this as completed Apr 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Feature] Templates API Related to API powering block template functionality in the Site Editor Needs Technical Feedback Needs testing from a developer perspective. [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

3 participants