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/02c6fac6a4bad5c81958d93248622392 to your computer and use it in GitHub Desktop.
Save taricco/02c6fac6a4bad5c81958d93248622392 to your computer and use it in GitHub Desktop.
/*** Inject GenerateBlocks for Reusable Blocks
@link https://docs.generateblocks.com/article/adding-content-sources-for-dynamic-css-generation/
Set the CSS Print Method in "GenerateBlocks > Settings" to "Inline Embedding"
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_filter('generateblocks_do_content', function ($content) {
$post_ids = array();
if (is_page_template('block-editor-template1.php')) {
$post_ids = array(12);
} /* With Sponsor Reusuable Block */
if (is_page_template('block-editor-template2.php')) {
$post_ids = array(34);
} /* MatchPlay Header Reusuable Block */
if (is_page_template('block-editor-template3.php')) {
$post_ids = array(56, 87);
} /* Cup Header & Footer Reusuable Blocks */
if (is_page_template('block-editor-template4.php')) {
$post_ids = array(90);
} /* No Sponsor Reusuable Block */
foreach ($post_ids as $post_id) {
if (has_blocks($post_id)) {
$block_element = get_post($post_id);
if (!$block_element || 'wp_block' !== $block_element->post_type) {
return $content;
}
if ('publish' !== $block_element->post_status || !empty($block_element->post_password)) {
return $content;
}
$content .= $block_element->post_content;
}
}
return $content;
});
OLD VERSION - One Reusable Block per Page Template
/*** Inject GenerateBlocks for Reusable Blocks
@link https://docs.generateblocks.com/article/adding-content-sources-for-dynamic-css-generation/
Set the CSS Print Method in "GenerateBlocks > Settings" to "Inline Embedding"
–––––––––––––––––––––––––––––––––––––––––––––––––– ***/
add_filter('generateblocks_do_content', function ($content) {
$post_id = 0;
if (is_page_template('block-editor-template1.php')) {
$post_id = 12;
} /* With Sponsor Reusuable Block */
if (is_page_template('block-editor-template2.php')) {
$post_id = 34;
}
if (is_page_template('block-editor-template3.php')) {
$post_id = 56;
}
if (is_page_template('block-editor-template4.php')) {
$post_id = 78;
} /* No Sponsor Reusuable Block */
if (has_blocks($post_id)) {
$block_element = get_post($post_id);
if (!$block_element || 'wp_block' !== $block_element->post_type) {
return $content;
}
if ('publish' !== $block_element->post_status || !empty($block_element->post_password)) {
return $content;
}
$content .= $block_element->post_content;
}
return $content;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment