About WordPress ShortCodes

26 July 2013

Sydney: Shortcodes are that nifty little syntax that you can use on your blog in pages or posts. All you need to do to use them is put the syntax or the shortcodes in the square brackets and you can get some great functionality in your post without a lot of inline code. The problem is all the themes do not have the same shortcodes, neither does WordPress have any standard list of shortcodes enabled for all themes, by default.

Enabling Shortcodes

To make shortcodes obtainable, they must be registered in your present theme. Or else, it’s like calling a telephone number that does not exist. But having a valid telephone number does not actually mean that you can get to the person you are hoping to reach. The number must be linked to the person or company you want to reach and have a conversation with. Let us look at how shortcodes work.

There are 3 things that you need to have for a short code to work:

  1. The shortcode: It is the syntax or text that you want to use in your posts and pages, enclosed in the square brackets.
  2. Shortcode registration: The shortcode that you want to use must be registered or declared in your theme’s functions.php file. This is like having a valid telephone number, a number that rings.
  3. Shortcode function: The shortcode function is the core of your shortcode. It is the code that will be processed and will give you the results that you want – the person you want to call. It can be anything, a simple display of information or a complex query to your database.

Creating Shortcodes

The best part is you can generate shortcodes for any function. You can write a function from the beginning, or you can employ an existing function to create new shortcodes. Most paid themes come with some shortcodes, but they may not fully satisfy your wants.

Putting a short author bio at the end of each post is one of the most common features that any blog with many authors will want. I know there are lots of plugins that can aid you do this. But if you are reluctant to burdening your WordPress set up with extra code, you can just write a new shorcode.

Here’s what you require to do –

Step 1: Write a new function for the shortcode.

To display your author bio information in the WordPress profile, you can add the following function to the functions.php file.

function authorbio() { return get_the_author_meta (description); }

The function authorbio() displays the biographical information in the user’s profile. To do this, the new function uses the existing WordPress function.

Step 2: Add the shortcode below the function.

This will register your new shortcode in the theme you are using.

add_shortcode( ‘authorinfo’, ‘authorbio’);

Here, the first argument in the bracket is the shortcode name or syntax that is authorinfo. The second argument is the name of the function that you want the shortcode to process. In this case it is the function that we defined in Step1. So now you have a telephone number and the number is associated with the person you want to call.

Step 3: Add the shortcode at the end of the post.

[authorinfo]

This will display the bio information of the author of the post as defined on the author’s Profile page. You can add as many arguments as you want to the author meta function as you like and even customize the way the author bio appears on your blog.

Read more: WordPress Web Development

Why Fortune Innovations?

  • Great value for your money. Services offered at most competitive cost

  • We try hard to excel in client expectation by providing client requirement utmost priority.

  • We believe in offering complete solution to customers by extending support even after completion of project and helping them leverage business growth globally through complete digital marketing.

  • Knowledge of latest technology and sophisticated tools allows us to build dynamic and responsive websites and portals to support your business.

  • Businesses have realized importance of top-notch website design in today's competitive marketplace and we have earned their trust by regularly delivering uppermost standards.

  • WordPress Development in Sydney
  • Drupal Development in Sydney
  • Joomla Development in Sydney
  • eCommerce Magento Sydney
  • Web Development Sydney
  • Web Design Sydney
  • jQuery development Sydney
  • Zend framework development Sydney
  • Airline IBE GDS Integration Navitaire Sydney
  • Airline IBE GDS Integration Aamadeus Sydney