Created
June 7, 2017 04:05
-
-
Save DNA/efd55703f058df4a31abdcd1cd4c615f to your computer and use it in GitHub Desktop.
WP shortcodes to apply bootstrap grid
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 | |
// [col size="foo-value"] | |
// Create the function that will handle the shortcode | |
function grid_column($attributes, $content = null) { | |
// shortcode_atts is used to define default attribute values | |
$attributes = shortcode_atts(array('size' => '12'), $attributes); | |
// keep applying shortcodes to content | |
$content = do_shortcode($content); | |
return "<div class='col-md-{$attributes['size']}'>$content</div>"; | |
} | |
// Register the shortcode | |
add_shortcode( 'col', 'grid_column' ); | |
// [row] | |
function grid_row($attributes, $content = null) { | |
return '<div class="row">' . do_shortcode($content) . '</div>'; | |
} | |
add_shortcode( 'row', 'grid_row' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment