RSVPMaker Now Dynamically Creates a Template for Block Themes

When you activate a full-site editing block theme (or activate RSVPMaker on a site that uses one of those themes), the plugin will now create a template for the rsvpmaker post_type based on that theme’s single post template. The major tweaks are to remove the blocks that display the post date (which can be confusing when emphasized more prominently than the event date) and post author.

You can then make further changes to the template, using the Full Site Editing feature, according to however you would like event posts to be displayed.

A dynamically created template for a custom post type

How it Works

With a full-site editing theme, WordPress checks for the existence of a database entry corresponding to a customized version of the template for the index, archive, page, or post to be displayed. If none is found, it defaults to loading the HTML file distributed with the theme. For example, if there is no ‘single’ template in the database for a single blog post, it will load ‘single.html’ from the template directory in the theme folder.

For an RSVPMaker event post, it will check for ‘single-rsvpmaker’ in the database or ‘single-rsvpmaker.html’ in the theme.

This means I can create a template specific to RSVPMaker posts as a database entry even though the theme doesn’t include a single-rsvpmaker.html. For most themes, the template used for single blog posts is probably close to how an event should be displayed, but maybe not exactly. A lot of themes will display the date a post was published prominently, when the date of the event is what you would really like to emphasize. So my altered version for events removes the standard date block.

This automated alteration of the single template works well on Twenty Twenty-Two, where the date and author blocks are normally placed at the bottom of each post, right before the blocks for category and taxonomy tag display.

With other themes, you might wind up with an obvious blank spot on the page where the post date was supposed to go. But thanks to the magic of Full Site Editing, you should be able to fix problems like that fairly easily. In other words, if there’s a wrapper block that normally contains the date block, you can remove that whole section.

Details for Developers

Here is how I dynamically create a template for a custom post type.

The code below is a simplified excerpt of what I’m using in the plugin. I use get_block_templates() to retrieve an array of template objects, including both those recorded in the database and those distributed with a theme. Assuming it finds a ‘single’ template, it filters out the date and author blocks and creates a new entry in the posts table with post_type set to ‘wp_template’ and ‘single-rsvpmaker’ in the post name field. The slug for the theme is added to the taxonomy for that post.

If you switch between full site editing themes, you may wind up with several versions of this in the post table but only the one for the current theme will be displayed in the editor.

Leave a comment