Create Custom Shortcode in Gutenberg

Working with Gutenberg, I’ve learned how to build custom blocks to show content inline on a page, but I thought there could be an easier way that building a block, or a custom template.With a custom shortcode (whether it links to the template with the block to show, or includes code to displays additional options like category or number of items), building custom blocks and templates is less necessary.

function my_form_shortcode() {
    ob_start();
    get_template_part('my_form_template');
    return ob_get_clean();   
} 
add_shortcode( 'my_form_shortcode', 'my_form_shortcode' );

Source.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.