What is WordPress Shortcode?

WordPress shortcodes are brilliant. They give you so much flexibility in the manner you deliver content, and their use will simplify use of integrated functions for the less tech-savvy. In a sense, they are an alternative to allowing PHP execution delivering dynamic content within a post. You can create simple functions that will easily deliver content within a post or parse text in a certain manner with the use of simple pre-defined code.

Basically, some code (shortcode) within your post is recognised by WordPress and converted into other more useful content as defined by a function designed to accomplish a particular task.

This video from WordPress shows how easy it it to insert a YouTube (and other) videos into your WordPress.com post using shortcode rather than using the provided embed code. Think of it as kind of “BBcode“. Shortcode = shortcut.

Here’s the simple “Hello, World” example that WordPress uses on its website to describe the basic principles of shortcode use.

function hello() {  
return 'Hello, World!';  
}
add_shortcode('hw', 'hello');

If you posted this code into your functions.php file, or in the case of Thesis, your custom_functions.php file, including the shortcode of [hw] into the html component of your WordPress editor (into a saved post) would output “Hello, World” in its place.

Read about shortcode here and here on the WordPress website.

We’ll post examples of its use soon.

First Name:
Your Email Address:
 


If you liked this article, you may also like:

  1. Website Snapshots with WordPress Shortcode
  2. Convert Currency on your Website or in a WordPress Post (with Shortcode)
  3. [Shortcode] Include an RSS feed in a post or page with shortcode
  4. Add shortcode into a WordPress sidebar
  5. [Shortcode] examples [3] – Text Boxes
About Marty

is a passionate web developer from Sydney, Australia. He owns about 600 websites and makes a healthy living from working the web. As a day job, he works as a pilot for an international airline. Follow Marty on Twitter or Google+.

Trackbacks

  1. [...] Continuing with the ongoing series of posts on shortcode, here’s some examples of how you can fancy up your posts – or use styled elements in a [...]

Speak Your Mind

*