Created
February 18, 2024 15:11
-
-
Save taricco/39f06f05d0d0a998039098e22eed48a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** 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