Add a shortcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function my_shortcode_function( $atts ) {
 
      $atts = shortcode_atts(
	   array(
	     'message' => 'My default message',
	     'class'   => 'default'
	   ), 
	   $atts);
 
      $result  = '<div class="' . esc_attr( $atts['class'] )  . '">' . $atts['message'] . '</div>'; 
      return $result; 
} 
 
add_shortcode('myshortcode', 'my_shortcode_function'); 
 
/************ 
 
usage :
[myshortcode message="This is my shortcode text" class="test"] 
 
If the shortcode produces a lot of HTML use ob_start to capture output and convert to string.
 
ob_start(); 
......... 
return ob_get_clean(); 
 
NOTE: shortodes always require returned values, not echo of values.
*/

http://codex.wordpress.org/Shortcode_API
http://codex.wordpress.org/Function_Reference/add_shortcode