On December 14, 2011 In CMS with , , tags

WordPress shortcode inside and outside

We all know how to create and use shortcodes. it all starts by creating simple php function and then adding function to shortcode inside functions.php.

<?php function function_name(){
return ''; // Enter the values to be printed, inside single quotes 
// Adding hook shortcode for the function_name

Using shortcode inside post/page is really simple, we just need to add shortened function name inside square brackets

[fn] //this return the value of the function

if we are going to use shortcodes inside theme files, we should print the shortcode using do_shortcode function.

<?php echo do_shortcode('[fn]'); ?>

Thanks to WP Codex for detailed notes on shortcodes