So Easy Even a Chimp Can Do It!
RSS icon Email icon Bullet (black)
  • More WordPress Short Codes - Mastering The Short Code

    Mastering ShortCodes
    Here is a great article from Smashing Magazine on WordPress Shortcodes. I didn’t ever think of setting up custom shortcodes.

    1. Open the functions.php file in your theme. If the file doesn’t exists, create it.
    2. First, we have to create a function to return the “Hello World” string. Paste this in your functions.php file:
    function hello() {
    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:
    add_shortcode(’hw’, ‘hello’);

    The first parameter is the shortcode name, and the second is the function to be called.
    4. Now that the shortcode is created, we can use it in blog posts and on pages. To use it, simply switch the editor to HTML mode and type the following:
    [hw]

    You’re done! Of course, this is a very basic shortcode, but it is a good example of how easy it is to create one.

    There are steps for adding your own shortcodes for twitter, rss readers, subscribe to rss, adsense, and wordpress database lookups.

    Here is another example of a shortcode for downloading a file. This has all the instructions to create the plugin and use the short code in your posts:

    Using Wordpress Shortcode To Create Beautiful Download Boxes
    Since shortcode was introduced in Wordpress 2.5 it’s been possible to do many cool things. Everything from simple donate buttons to more advance things. In this article I will show you a simple but efficient way to create one of those download-boxes that I and many other use on their blogs.

    Remember if you are creating shortcodes you need to add them to the functions.php file. If you are upgrading your system automatically you will want to keep a copy of all your new shortcodes and add them back to the updated files. If you don’t they could stop working at some point (when functions.php is replaced).

    Enjoy!

    Post to Twitter Post to Plurk Plurk This Post Post to Digg Digg This Post Post to Ping.fm Ping This Post Post to StumbleUpon Stumble This Post

  • WordPress Short Codes in Templates

    How do you put shortcodes in your template files?

    I came across a problem the other day.  I found a plugin I wanted to use but it didn’t have any php calls to invoke it, only WordPress shortcodes.  I scanned the forums and found a very good alternative from Dukessa.  By using a WordPress call to the short code  I could add the call to the header.php file.

    Here is the call format:

    <?php echo do_shortcode(’[shortcode]‘); ?>

    Here is an example of how to embed a short code in a header.php file for NextGEN Gallery plugin.

    <?php echo do_shortcode(’[slideshow id=1]‘); ?>

    Give it a try, it works great.

    Post to Twitter Post to Plurk Plurk This Post Post to Digg Digg This Post Post to Ping.fm Ping This Post Post to StumbleUpon Stumble This Post

Bad Behavior has blocked 697 access attempts in the last 7 days.

Twitter links powered by Tweet This v1.6.1, a WordPress plugin for Twitter.