Skip to content

Instantly share code, notes, and snippets.

@facelordgists
Created April 22, 2013 02:08
Show Gist options
  • Save facelordgists/5431995 to your computer and use it in GitHub Desktop.
Save facelordgists/5431995 to your computer and use it in GitHub Desktop.
WORDPRESS: Shortcode cleanup function that converts hyphens into underscores
<?php
function nt_cleanup_shortcode_atts ($atts){
$atts_new = array();
foreach ($atts as $key => $value) {
if(is_numeric($key) && substr_count($value, "=")){
list($key,$value) = explode("=", $value);
$atts_new[str_replace("-", "_", $key)] = $value;
}
$atts_new[$key] = $value;
}
return $atts_new;
}
add_shortcode('column', 'nt_column');
function nt_column($atts, $content = null)
{
if($content == null) return '';
$atts = shortcode_atts(array(
'large' => '',
'small' => '',
'push' => '',
'pull' => '',
'large_centered' => false,
'small_centered' => false,
'large_offset' => '',
'small_offset' => '',
'class' => '',
'style' => '',
'p' => 'true',
), nt_cleanup_shortcode_atts($atts));
extract($atts);
$content = parse_shortcode_content( $content );
$out = '<div class="columns';
if( $large || $small ){
if($large)$out .= ' large-' . $large;
if($small)$out .= ' small-' . $small;
} else {
if($small)$out .= ' small-12' . $small;
}
if($push)$out .= ' push-' . $push;
if($pull)$out .= ' pull-' . $pull;
if($large_centered)$out .= ' large-centered';
if($small_centered)$out .= ' small-centered';
if($large_offset)$out .= ' large-offset-' . $large_offset;
if($small_offset)$out .= ' small-offset-' . $small_offset;
if($class)$out .= ' ' . $class;
$out .= '"';
if($style)
$out .= 'style="'. $style .'"';
$out .= '>';
if ( $p == 'false' ) $content = preg_replace('#<p>|</p>#', '', $content);
$out .= $content;
$out .= '</div>';
return $out;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment