Skip to content

Instantly share code, notes, and snippets.

@timkinnane
Created April 7, 2013 23:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timkinnane/5333109 to your computer and use it in GitHub Desktop.
Save timkinnane/5333109 to your computer and use it in GitHub Desktop.
Wordpress shortcode example
<?php
// MyShortcode usage [myshortcode greeting="Hello" who="World"]
function myshortcode_func( $atts, $content = null ) {
// use given attributes or defined defaults
extract( shortcode_atts( array(
'greeting' => '',
'who' => ''
), $atts ) );
// do something (e.g. out put Label : Value)
$html = trim($label). " : ".trim($attr);
// do something with content. e.g. [myshortcode]Hello World[/myshortcode]
// outputs Computer says: Hello World
if ($content != null) $html = "Computer says: ".trim($content);
return $html;
}
add_shortcode('myshortcode', 'myshortcode_func');
?>
<?php
// MyShortcode usage [myshortcode greeting="Hello" who="World"]
function myshortcode_func( $atts, $content = null ) {
// use given attributes or defined defaults
extract( shortcode_atts( array(
'greeting' => '',
'who' => ''
), $atts ) );
// do something (e.g. out put Label : Value)
$html = trim($label). " : ".trim($attr);
// do something with content. e.g. [myshortcode]Hello World[/myshortcode]
// outputs Computer says: Hello World
if ($content != null) $html = "Computer says: ".trim($content);
return $html;
}
add_shortcode('myshortcode', 'myshortcode_func');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment