You can even define default content for new posts that already has a gallery block. There can even be a warning that any other added content will be discarded, since the warning would also be discarded by such enforcement.
If other content is required besides the gallery, it could be accomplished through custom fields. The $post->post_content in code would be strictly for gallery content only.
]]>It sounds like you like the default gallery block but don’t want to allow the client to add other information into the editor. What if you gave them the editor, but had enforcement code that discards any content outside of a single gallery block?
Yes, it would be great! ??
You can even define default content for new posts that already has a gallery block. There can even be a warning that any other added content will be discarded, since the warning would also be discarded by such enforcement.
How to do this?
If other content is required besides the gallery, it could be accomplished through custom fields. The $post->post_content in code would be strictly for gallery content only.
I made custom fields already. Thank you!!
]]>add_filter( 'the_editor_content', function ( $content ) {
if ( $content ) return $content;
else return '[gallery]';
});
If there is a way to do the same for the block editor in PHP, I’m unaware of what it is. It should at least be possible to insert something via JavaScript/jQuery.
Which style of editor is used impacts which regexp is used to identify the gallery element within other potential content. Whichever is used, my thought was to preserve the first matching content and discard everything else. This could be a problem should the user enter a second gallery, ignoring the first. There’s no way for code to know the “right” gallery to preserve.
To do this enforcement, use the “wp_insert_post_data” filter. Your callback is passed most post data, of which code can alter as it sees fit just before WP inserts or updates the post in the DB.
]]>