Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taricco/39f06f05d0d0a998039098e22eed48a0 to your computer and use it in GitHub Desktop.
Save taricco/39f06f05d0d0a998039098e22eed48a0 to your computer and use it in GitHub Desktop.
/*** Set default editor content for CPT using a specific Synced Pattern
NOTE: This action will overwrite the post content every time the post is saved.
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
function add_or_replace_content_with_synced_pattern_for_video_posts($data, $postarr) {
// Only target the 'video' post type
if ($data['post_type'] == 'cpt_name') {
// Define your reusable block ID
$reusable_block_id = 123; // Replace 123 with your actual reusable block ID
// Prepare the reusable block content
$reusable_block_content = sprintf('<!-- wp:block {"ref":%d} /-->', $reusable_block_id);
// Set the post content to the reusable block content
$data['post_content'] = $reusable_block_content;
}
return $data;
}
add_filter('wp_insert_post_data', 'add_or_replace_content_with_synced_pattern_for_video_posts', '99', 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment