Posts

Showing posts from May 8, 2011

Wordpress :Creating a Simple Shortcode

The thing to remember with shortcodes is that they're very easy to create. If you know how to write a basic PHP function, then you already know how to create a WordPress shortcode. For our first one, let's create the well-known "Hello, World" message. Open the functions.php file in your theme. If the file doesn't exists, create it. First, we have to create a function to return the "Hello World" string. Paste this in your functions.php file: view source print ? 1 function hello() { 2      return 'Hello, World!' ; 3 } Now that we have a function, we have to turn it into a shortcode. Thanks to the add_shortcode() function, this is very easy to do. Paste this line after our hello() function, then save and close the functions.php file: view source print ? add_shortcode( 'hw' , 'hello' ); The first parameter is the shortcode name, and the second is the function to be called. Now that the shortcode is create...