Shortcodes!
10 Apr 2011 No Comments
Hello WorldWow. Just learned an awesome WordPress feature, Shortcodes! Shortcodes are super simple to create and I just know I’m going to have many many opportunities to use these in the future. As a test the “Hello World” you see above was created with a simple shortcode and I’ll show you how simple it is to create a short code.
Shortcodes are created in the functions.php file in your theme directory. Open functions.php up and pick a place to put your code. The first thing you are going to do is create a simple function. Try this one.
function Hello() {
return “Hello World”;
}
Then below this you will create the shortcode by typing this…
add_shortcode( ‘hw’, ‘Hello’);
As you can see the first parameter will be the name of your shortcode (hw). The next parameter is the function that your shortcode will execute (Hello).
Now you are free to use this shortcode in any of your pages or posts. Just place Hello World anywhere in your posts or pages in the wordpress editor. When you go to view the post or the page you will see “Hello World”.