The WordPress shortcode is a wonderful tool. Shortcodes allow developers to give control of their code-snippets to the WordPress-administrators.
Shortcodes developers allow users to place/embed the developer’s code anywhere they like.
The developer writes the output, and the user adds the shortcode in their WordPress editor wherever they would like to output that code.
Shortcodes Accept “arguments”.
Arguments are declarative statements (basically x = “this”) which can modify the shortcode output.
- This shortcode, for example: [hello name=”Bob” weather=”rainy”]
- … Might output the following: “Hi Bob! It’s another beautiful, rainy day”
- Whereas: [hello name=”jane” weather=”sunny”]
- … Would output: “Hi Jane! It’s another beautiful, sunny day”
Here’s a “dead-simple” shotcode example (You can find this and more in the WordPress.org docs… But I phrase things so nicely, you may as well just read about them here.)
... So when we type [my-shortcode] in to the wordpress editor (or widget areas if you have that filter turned on) we get: I'm the best.
Alright, let's continue kicking-ass. Next step is to make it easier to modify the output of this shortcode... If you've worked with php for more then 20 minutes you've probably figured out that strings can suck.
What if you want your short-code to return a bunch of html...
$output .= "the";
$output .= "best