Created
April 7, 2013 23:36
-
-
Save timkinnane/5333109 to your computer and use it in GitHub Desktop.
Wordpress shortcode example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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