Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
WP shortcodes to apply bootstrap grid
// [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