Shortcodes, output buffering, and WordPress functions

Should I just bring these forms out into templates instead?

It depends on the form, and you haven’t printed much detail about what your forms do. Shortcodes are nice but are not the right tool for every job.

I would:

  1. Prefer a dedicated template to a shortcode, especially for long forms. You start to get into having to handled $_POST or $_GET data in the shortcode or check for the presence of that data in your header, or other such, and that gets messy. Plus the shortcode is overhead that may be avoidable.
  2. Consider an exception to Rule #1 and make a shortcode, if the form has to be reused on multiple pages, or if such reuse is at least a plausible possibility. Honestly, if it fails the “reuse” test I don’t see the point of the shortcode at all.
  3. Consider an exception to Rule #1 and #2 if you need editable content around the shortcode.
  4. If you are writing a plugin, a shortcode is one of your better choices. You could instruct people to create a page template and insert some code, or alter rewrite rules to make your own pseudo-page but the first is off-putting for most users and the second is complex. Even asking people to paste a shortcode into the post body can cause a panic, but at some point humanity has to learn to use computers.

I am sure there are other concerns but those are the ones that stand out to me.

Leave a Comment