Sometimes you want to insert Gutenberg blocks into Oxygen Template, this small code snippet will help you do so. Giving all credit to David Browne.

add_shortcode('wp_oxy_reusable_block', 'lit_reusable_block_sc');
/**
 * Add a shortcode to allow resuable blocks, that are created in WP editor, to be inserted in Oxygen templates using their IDs
 *
 * Sample usage: [wp_oxy_reusable_block id='2543']
 */
function lit_reusable_block_sc( $atts ) {

    	$attributes = shortcode_atts(
    array(
      'id' => null
    ), $atts );
  
  $output = do_blocks( get_the_content('', '', get_post($attributes['id']) ) );
  
  	return $output;

}

Credit:

GiangLe.DEV

My name is Giang, a Vietnamese guy living in Thanh Hoa City, Vietnam. I am a WordPress Developer, learning to master WordPress and Laravel PHP Framework.

Leave a Reply

avatar
  Subscribe  
Notify of
Close Menu