Skip to content

Instantly share code, notes, and snippets.

@bradpotter
Last active June 1, 2021 15:12
Show Gist options
  • Select an option

  • Save bradpotter/a236b6f93a7b5655956b872f7cee776f to your computer and use it in GitHub Desktop.

Select an option

Save bradpotter/a236b6f93a7b5655956b872f7cee776f to your computer and use it in GitHub Desktop.
Place a reusable Gutenberg block via a Genesis hook. (Where 956 is the Post ID of your reusable block)
add_action( 'genesis_before_footer', 'my_custom_query' );
function my_custom_query() {
$post_id = 956;
$queried_post = get_post($post_id);
echo $queried_post->post_content;
}
@johnstonphilip

johnstonphilip commented Mar 31, 2021 •

Copy link
Copy Markdown

You may want to run this through do_blocks like this:

add_action( 'genesis_before_footer', 'my_custom_query' );
function my_custom_query() {
 
	$post_id = 956;
	$queried_post = get_post($post_id);
	echo do_blocks( $queried_post->post_content );
}

Additionally, for security reasons it's a good practice to wrap all output in a proper escape function:
https://developer.wordpress.org/themes/theme-security/data-sanitization-escaping/#escaping-securing-output

@johnstonphilip

johnstonphilip commented Mar 31, 2021 •

Copy link
Copy Markdown

Also may be worth mentioning that if you are using shortcodes at all in the content, you'll also need to run it through do_shortcode for those to get rendered out properly.

@johnstonphilip

Copy link
Copy Markdown

Also worth mentioning that embeds won't work with this unless you also wrap in

// Handle embeds.
global $wp_embed;
$content = $wp_embed->autoembed( $content );

This is what core does for widgets here:
https://github.com/WordPress/WordPress/blob/1314542c50e2ad2075b1304df20471febffb8fad/wp-includes/widgets/class-wp-widget-block.php#L75-L77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment