Last active
August 21, 2016 15:27
-
-
Save danielpataki/83b0f48c5851f748d3ed to your computer and use it in GitHub Desktop.
Shortcodes
This file contains 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
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' ); |
This file contains 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
// 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' ); |
This file contains 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 echo do_shortcode( '[gallery ids="3,14,423" columns="3"]' ) ?> |
This file contains 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
// 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