Skip to content

Instantly share code, notes, and snippets.

@DNA
Created June 7, 2017 04:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DNA/efd55703f058df4a31abdcd1cd4c615f to your computer and use it in GitHub Desktop.
Save DNA/efd55703f058df4a31abdcd1cd4c615f to your computer and use it in GitHub Desktop.
WP shortcodes to apply bootstrap grid
<?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