Custom Shortcodes

USEFUL? 0

If you don’t have an existing shortcode to get the value you need, you can write a custom shortcode. If you’re familiar with PHP, it’s really easy.

All you do is define a shortcode tag and a function that handles processing that tag.

Here’s a basic template to create a [my_special_shortcode] shortcode:

add_shortcode( 'my_special_shortcode', 'my_special_shortcode_function' );
function my_special_shortcode_function( $atts , $content ){
  return "hey I'm a custom shortcode!";
}

Which just means that when the following shortcode is processed:

[my_special_shortcode]

it’ll be replaced by the text

hey I'm a custom shortcode!

For full details on how to write a custom shortcode, use custom attributes and content, etc, please review the following resources:

Creating Custom shortcodes
WordPress shortcode API