Skip to content

Instantly share code, notes, and snippets.

@gfargo
Last active August 4, 2016 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfargo/6e80e0ae159328258c4d3c23a1740755 to your computer and use it in GitHub Desktop.
Save gfargo/6e80e0ae159328258c4d3c23a1740755 to your computer and use it in GitHub Desktop.
Example WP Shortcodes
//
// Callout Shortcode
//
function callout_shortcode ($atts, $content = null) {
extract(shortcode_atts(array(
'title' => 'Product / Callout',
'subtitle' => '',
'text' => 'lorem content',
'image' => 'http://path/to/logo',
'align' => 'left',
'parallax' => true,
), $atts));
$returnContent = '';
ob_start();
?>
<div class="callout-container callout-<?php echo esc_attr( $align ); ?>" data-parallax="<?php echo esc_attr( $parallax ); ?>">
<div class="callout-content">
<h3 class="callout-header">
<?php echo esc_html( $title ); ?>
<?php if ( ! empty( $subtitle ) : ?>
<small><php echo esc_html( $subtitle ); ?></small>
<?php endif; ?>
</h3>
<p class="callout-content"><?php echo esc_html( $text ); ?></p>
</div>
<div class="callout-image">
<img src="<? echo esc_attr( $image ); ?>" alt="<?= $title ?>">
</div>
</div>
<?php
$returnContent = ob_get_clean();
return $returnContent;
}
add_shortcode("callout", "callout_shortcode");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment