Skip to content

Instantly share code, notes, and snippets.

@alanef
Created October 22, 2020 16:18
Show Gist options
  • Select an option

  • Save alanef/11b7a83559f88f18a3869ed8510d1ddc to your computer and use it in GitHub Desktop.

Select an option

Save alanef/11b7a83559f88f18a3869ed8510d1ddc to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: Test Shortcode
Plugin URI: https://fullworks.net
Description: Test Shortcode Gutenberg content
Version: 1.0
Author: alan
Author URI: https://fullworks.net
License: GPL2
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
add_shortcode( 'test_display', function ( $atts ) {
$a = shortcode_atts( array(
'id' => 0,
), $atts );
$return = '';
$blocks = parse_blocks( get_the_content( null, false, $a['id'] ) );
foreach ( $blocks as $block ) {
$return .= apply_filters( 'the_content', render_block( $block ) );
}
return $return;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment