Skip to content

Instantly share code, notes, and snippets.

@gicolek
Created August 26, 2015 12:59
Show Gist options
  • Save gicolek/832e27a7ac49f238cbc2 to your computer and use it in GitHub Desktop.
Save gicolek/832e27a7ac49f238cbc2 to your computer and use it in GitHub Desktop.
Sample shortcode
<?php
add_shortcode( 'div', 'wp_doin_div_shortcode' );
function wp_doin_div_shortcode($atts, $content = null) {
ob_start();
// let's fetch all of the arguments of the shortcode
$atts = shortcode_atts( array(
'class' => 'wp-doin',
'heading' => 'Heading',
'subheading' => 'Subheading',
), $atts );
// let's output the contents of the shortcode in a custom div
?>
<div class="<?php echo $atts['class']; ?>">
<h2><?php echo $atts['heading']; ?></h2>
<h3><?php echo $atts['subheading']; ?></h3>
<?php echo do_shortcode( $content ); ?>
</div>
<?php
return ob_get_clean();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment