add_shortcode

Add hook for shortcode tag.

Description

add_shortcode( (string) $tag, (callable) $func ); 

There can only be one hook for each shortcode. Which means that if another plugin has a similar shortcode, it will override yours or yours will override theirs depending on which order the plugins are included and/or ran.

Simplest example of a shortcode tag using the API:

Example with nice attribute defaults:

// [bartag foo="bar"]
function bartag_func($atts) ;
}
add_shortcode('bartag', bartag_func);

Example with enclosed content:

// [baztag]content[/baztag]
function baztag_func($atts, $content='') 
add_shortcode('baztag', baztag_func);

Parameters (2)

0. $tag (string)
Shortcode tag to be searched in post content.
1. $func (callable)
Hook to run when shortcode is found.

Usage

  1. if ( !function_exists( 'add_shortcode' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/backpress/functions.shortcodes.php'; 
  3.  
  4. // Shortcode tag to be searched in post content. 
  5. $tag = ''; 
  6.  
  7. // Hook to run when shortcode is found. 
  8. $func = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = add_shortcode($tag, $func); 
  12.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/backpress/functions.shortcodes.php  
  1. function add_shortcode($tag, $func) { 
  2. global $shortcode_tags; 
  3.  
  4. if ( is_callable($func) ) 
  5. $shortcode_tags[$tag] = $func;