Wordpress Shortcodes
<?php
//----------------------------------------------
// Shortcodes
//----------------------------------------------
function my_shortcode_routine($args, $content = null) {
// $args = array('key1' => 'value1', 'key2' => 'value2')
$return = '';
$tags = array("<p>", "</p>");
$content = str_replace($tags, "", $content);
$content = str_replace(">", '> ', $content);
if($args['layout'] == 'two-horizontal') {
$return = '<div class="img-wrapper">' . $content . '</div>';
}
elseif($args['layout'] == 'three-horizontal') {
$content = str_replace("> ", '> ', $content);
$return = '<div class="img-wrapper wrap-three">' . $content . '</div>';
}
// return the result
return $return;
}
add_shortcode('shortcode_name', 'my_shortcode_routine');
// Usage: [shortcode_name key1="value1" key2="value2"]
//----------------------------------------------
// Shortcodes using Output Buffer
//----------------------------------------------
function my_shortcode_cb() {
ob_start(); ?>
<div class="my-div">
Fun stuff here.
</div>
<?php return ob_end_clean();
}
add_shortcode( 'my_shortcode', 'my_shortcode_cb' );
?>