Skip to content

Instantly share code, notes, and snippets.

@bradpotter
Last active Jun 1, 2021
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@johnstonphilip johnstonphilip commented Mar 31, 2021

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

This comment has been minimized.

Copy link

@johnstonphilip johnstonphilip commented Mar 31, 2021

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

This comment has been minimized.

Copy link

@johnstonphilip johnstonphilip commented Jun 1, 2021

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