Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active August 21, 2016 15:27
Show Gist options
  • Save danielpataki/83b0f48c5851f748d3ed to your computer and use it in GitHub Desktop.
Save danielpataki/83b0f48c5851f748d3ed to your computer and use it in GitHub Desktop.
Shortcodes
function shortcode_hello( $atts ){
$time = ( date('G') < 9 ) ? "good morning" : "good day";
return "Hello, and " . $time . ', my name is Daniel';
}
add_shortcode( 'hello', 'shortcode_hello' );
// Usage:
// [colorblock color='ff9900']
// Creates a small color swatch
function shortcode_colorblock( $atts ){
$atts = shortcode_atts( array(
'color' => '000000',
), $atts, 'colorblock' );
return "<div class='swatch' style='height:22px; width:50px; display:inline-block; color:#" . $atts['color'] . "'></div>";
}
add_shortcode( 'colorblock', 'shortcode_colorblock' );
<?php echo do_shortcode( '[gallery ids="3,14,423" columns="3"]' ) ?>
// Usage:
// [message type='alert']Note that we are closed due to renovatiosn for 2 weeks[/message]
function shortcode_message( $atts, $content ){
$atts = shortcode_atts( array(
'type' => 'success',
), $atts, 'message' );
return "<div class='alert " . $atts['type'] . "'>" . $content . "</div>";
}
add_shortcode( 'message', 'shortcode_message' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment