I’m trying to create custom shortcodes for bootstrap and am running into some difficulty. I have seen numerous articles that called for using do_shortcode($content) in place of just ($content), but can’t seem to get it to work.
My code is as follows in my functions.php file:
add_shortcode( 'container', 'container' );
add_shortcode( 'onefourth', 'onefourth' );
add_shortcode( 'onethird', 'onethird' );
add_shortcode( 'onehalf', 'onehalf' );
add_shortcode( 'twothirds', 'twothirds' );
add_shortcode( 'threefourths', 'threefourths' );
add_shortcode( 'fullwidth', 'fullwidth' );
function container ( $atts, $content = null ) {
return '<div class="container"><div class="row">' . do_shortcode($content) . '</div></div>';
}
// COLUMN SUPPORT
// One Fourth
function onefourth ( $atts, $content = null ) {
return '<div class="col-sm-3">' . $content . '</div>';
}
// One Third
function onethird ( $atts, $content = null ) {
return '<div class="col-sm-4">' . $content . '</div>';
}
// One Half
function onehalf ( $atts, $content = null ) {
return '<div class="col-sm-6">' . $content . '</div>';
}
// Two Thirds
function twothirds ( $atts, $content = null ) {
return '<div class="col-sm-8">' . $content . '</div>';
}
// Three Fourths
function threefourths ( $atts, $content = null ) {
return '<div class="col-sm-9">' . $content . '</div>';
}
// Full width
function fullwidth ( $atts, $content = null ) {
return '<div class="col-sm-12">' . $content . '</div>';
}
What am I missing? I get the container to output
<div class="container">
but cannot get any of the columns to output. I simple see, for example,
[onehalf] THE CONTENT [/onehalf].
I’ve also tried changing
return '<div class="col-sm-size">' . $content . '</div>';
to
return '<div class="col-sm-size">' . do_shortcode($content) . '</div>';
for each of the column shortcodes, and it still doesn’t work…
Any help would be greatly appreciated.
Thanks!