I use this shortcode very often: [foo]123[/foo].

I'd like to drag and drop a custom block in the block editor, instead of typing the shortcode (and making typos).

So how do I create a custom block, that just wraps that shortcode?

2 Answers 2

  1. First Add a normal Shortcode block and type the shortcode [foo]123[/foo]
  2. Then click More Options for the block and select Add to Reusable Blocks
  3. Then provide a name as Foo
  4. Next, time you can search and add the Foo block instead of typing the shortcode


  • I actually wanted a programmatic way to do this, but I see I didn't put that in the question. So your answer is valid. Thanks.
    – lonix
    Jan 18, 2020 at 4:46
  • I see. I didnt get that idea from the question. There should be a way to do it. Havent tried yet. Will update if i have time to check and find a solution Jan 18, 2020 at 5:32
  • 1
    Don't worry, your answer is valid for this question. Thanks!
    – lonix
    Jan 18, 2020 at 5:41

There is a way to do this via code: use the do_shortcode('[your-shortcode-name-here]') function. It's drop-dead simple. The doc is at https://developer.wordpress.org/reference/functions/do_shortcode/.

You can use a filter hook with the do_shortcode() function to make pretty much anything in WordPress shortcode-capable. For example, to enable shortcodes in the post titles, do this: add_filter('the_title', 'do_shortcode')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.