Skip to content

Instantly share code, notes, and snippets.

@scottnix
Created June 23, 2013 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottnix/5844103 to your computer and use it in GitHub Desktop.
Save scottnix/5844103 to your computer and use it in GitHub Desktop.
Responsive version of shortcode columns for WordPress. Haven't tested in ages, based on http://scottnix.com/wordpress-columns-shortcode/
function snix_clean_shortcodes($content) {
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
return $content;
}
add_filter('the_content', 'snix_clean_shortcodes');
function snix_responsive_boxes( $atts, $content = null ) {
extract(shortcode_atts(array(
'size'=> 'full-width', // full width box is default
'type' => '',
), $atts));
$size = ($size) ? ''.$size : '';
$type = ($type) ? ' '.$type : '';
if (strpos($size, "last") === false) {
return '<div class="' .$size.$type. ' responsive-box">' .do_shortcode($content). '</div>';
}
else {
return '<div class="' .$size.$type. ' responsive-box">' .do_shortcode($content). '</div><span class="cf"></span>';
}
}
add_shortcode('rbox', 'snix_responsive_boxes');
/* css */
/* responsive-box full width */
.responsive-box { width: 100%; clear: both;}
.responsive-box img { float: left; width: 35%; margin-right: 4%; }
.responsive-box p img { margin-bottom: 0; }
@media (min-width: 700px) {
/*
responsive box sizing - size=""
default is full width 100%
----------------------------------------------------*/
.one_half, .one_half_last { width:48%; }
.one_third, .one_third_last { width:30.66%; }
.two_third, .two_third_last { width:65.33%; }
.one_fourth, .one_fourth_last { width:22%; }
.three_fourth, .three_fourth_last { width:74%; }
.one_fifth, .one_fifth_last { width:16.8%; }
.two_fifth, .two_fifth_last { width:37.6%; }
.three_fifth, .three_fifth_last { width:58.4%; }
.four_fifth, .four_fifth_last { width:67.2%; }
.one_sixth, .one_sixth_last { width:13.33%; }
.five_sixth, .five_sixth_last { width:82.67%; }
.one_half, .one_third, .two_third, .three_fourth, .one_fourth, .one_fifth, .two_fifth, .three_fifth, .four_fifth, .one_sixth, .five_sixth { float: left; margin-right: 4%; }
.one_half_last, .one_third_last, .two_third_last, .three_fourth_last, .one_fourth_last, .one_fifth_last, .two_fifth_last, .three_fifth_last, .four_fifth_last, .one_sixth_last, .five_sixth_last { float: left; clear: right; }
.full-width { clear: both; }
.responsive-box { position: relative; margin-bottom: 1.4em; clear:none }
.responsive-box p img { margin-bottom: 1.4em; }
.full-width.responsive-box img { width: 100%; }
img[class*="align"], img[class*="wp-image-"] { height: auto; }
img.size-full { max-width: 100%; width: auto; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment