How to add a template via a plugin (podcast, woo, LMS)
Discussed in https://github.com/WordPress/developer-blog-content/discussions/185
Originally posted by bph December 14, 2023 This question came up quite a bit in the last few months. Example It might not be possible, as I still see this issue open: Add support for adding templates and template parts for plugins #42362
So this is more a placeholder Topic idea, when this is worked out in core.
This is the original issue https://github.com/WordPress/gutenberg/issues/41401
These Fukken Feelings Podcast©. You can find us on ALL Podcast Platforms and don't forget to follow us on all social media platforms @fukkenfeelings to stay up-to-date on all new episodes and behind-the-scenes content.
I have a solution for this: https://gist.github.com/justintadlock/cfcdcdf47ea785e84c8575dddc68ea37
There are several possibilities that could be explored based on the code in that Gist. It's specific to virtual pages, which is what I'm assuming is the biggest pain-point. But there are things that plugins can do now to make their "regular, non-virtual" templates editable in a block theme.
Anyone is welcome to take this code and run with it. I don't know what kind of bandwidth I'll have to fit another tutorial into my schedule in the immediate future, so I'll leave this topic unclaimed. But if no one picks it up, I'm OK with adding it to my list after the WP 6.5 update is out.
Just an update from my end: I still have #238 and #239 to work through over the next few weeks. After that, I'm happy to take this one on. It might be mid-to-late April. But I'll leave this unassigned in case someone wants to try their hand at it.
Chiming in here that this PR is very much underway: https://github.com/WordPress/gutenberg/pull/61577
I'm working on this here: https://docs.google.com/document/d/1df9U3h5umMpbIEXRp4K38F9oFXDRPAi_4VPvt0houGg/edit?usp=sharing
Test code currently here: https://github.com/justintadlock/devblog-plugin-templates
That's really cool, @justintadlock! Thanks for working on this. I see you used the .php extension for template files, is there any benefit of doing so instead of .html?
@Aljullu - Because the files have PHP code in them for things like internationalization. This is pretty typical when building default templates.
@Aljullu - Because the files have PHP code in them for things like internationalization. This is pretty typical when building default templates.
Oh, right, I missed the PHP snippets in some of them. It makes sense. :+1:
This one is ready for its first review: https://docs.google.com/document/d/1df9U3h5umMpbIEXRp4K38F9oFXDRPAi_4VPvt0houGg/edit?usp=sharing
@Aljullu - Any technical feedback you'd like to share is more than welcome as well.
Note: If testing code, this requires Gutenberg 19.1. Also, the post cannot be published until that version of Gutenberg is live.
I didn't test the code examples, but I read through it and everything looks good. Thanks for writing it, @justintadlock!
@justintadlock I completed the first review of the article and added a few comments. Looks great.
Moving this to second review.
We still have a couple of comments from the first review waiting for clarification/feedback in this ticket: https://github.com/WordPress/gutenberg/pull/61577
Finished second review. Just tiny little nitpicks. It's ready to publish
Social copy:
Coming in WordPress 6.7: Learn how to register block templates for plugin's custom post types, custom URLs, and more in this Developer Blog tutorial:
https://developer.wordpress.org/news/2024/08/29/registering-block-templates-via-plugins-in-wordpress-6-7/
Social post scheduled for September 4.