How do I create shortcodes for my wordpress themes?

See the Shortcode API article on the Codex for a tutorial and my Shortcode Plugin for some examples.

A very basic example for the functions.php:

/**
 * Shortcode for bloginfo()
 *
 * Usage: [bloginfo key="template_url"]
 *
 * @see http://codex.wordpress.org/Template_Tags/get_bloginfo
 * @source http://blue-anvil.com/archives/8-fun-useful-shortcode-functions-for-wordpress
 * @param array $atts
 * @return string
 */
function bloginfo_shortcode($atts)
{
    extract( shortcode_atts( array( 'key' => 'name' ), $atts ) );
    return get_bloginfo( $key );
}
add_shortcode( 'bloginfo', 'bloginfo_shortcode' );

Leave a Comment