Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active August 29, 2015 14:08
Show Gist options
  • Save danielpataki/9754ee800680d19c6717 to your computer and use it in GitHub Desktop.
Save danielpataki/9754ee800680d19c6717 to your computer and use it in GitHub Desktop.
Grid Shortcode
function my_code_output( $atts, $content ) {
return '<pre><code>' . $content . '</code></pre>';
}
add_shortcode('code', 'my_code_output');
[code type='javascript']
var array = [ 'Thud', 'Night Watch', 'Jingo' ];
[/code]
<pre><code>var array = [ 'Thud', 'Night Watch', 'Jingo' ];</code></pre>
[code]
$array = ( 'Thud', 'Night Watch', 'Jingo' );
[/code]
<pre><code>$array = ( 'Thud', 'Night Watch', 'Jingo' );</code></pre>
[row]
[column medium="6" large="3"]
Column 1 [/column][column medium="6" large="3"]
Column 2 [/column][column medium="6" large="3"]
Column 3 [/column][column medium="6" large="3"]
Column 4 [/column]
[/row]
function my_column( $atts, $content ) {
$atts = shortcode_atts( array(
'small' => 12,
'medium' => null,
'large' => null
), $atts );
$atts['medium'] = ( $atts['medium'] == null ) ? $atts['small'] : $atts['medium'];
$atts['large'] = ( $atts['large'] == null ) ? $atts['medium'] : $atts['large'];
extract( $atts );
$sizes = 'small-' . $small . ' medium-' . $medium . ' large-' . $large;
return '<div class="columns ' . $sizes . '">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'column', 'my_column');
function grid_styles() {
wp_register_style( 'grid', get_template_directory_uri() . '/css/grid.css', array(), null );
}
add_action( 'wp_enqueue_scripts', 'grid_styles' );
function my_row( $atts, $content ) {
wp_enqueue_style( 'grid' );
$content = preg_replace( "/\[\/column\](\<br \/\>|\<\/p\>.?\<p\>).?\[column/s", '[/column][column', $content );
return '<div class="row">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'row', 'my_row' );
function grid_styles() {
wp_enqueue_style( 'grid', get_template_directory_uri() . '/css/grid.css', array(), null );
}
add_action( 'wp_enqueue_scripts', 'grid_styles' );
<div class='row'>
<div class='small-12 medium-6 large-3 columns'> Column 1 </div>
<div class='small-12 medium-6 large-3 columns'> Column 2 </div>
<div class='small-12 medium-6 large-3 columns'> Column 3 </div>
<div class='small-12 medium-6 large-3 columns'> Column 4 </div>
</div>
[row]
[column medium="6" large="3"] Column 1 [/column]
[column medium="6" large="3"] Column 2 [/column]
[column medium="6" large="3"] Column 3 [/column]
[column medium="6" large="3"] Column 4 [/column]
[/row]
function my_row( $atts, $content ) {
$content = preg_replace( "/\[\/column\](\<br \/\>|\<\/p\>.?\<p\>).?\[column/s", '[/column][column', $content );
return '<div class="row">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'row', 'my_row' );
function my_row( $atts, $content ) {
return '<div class="row">' . do_shortcode( $content ) . '</div>';
}
add_shortcode( 'row', 'my_row' );
function my_code_output( $atts, $content ) {
$atts = shortcode_atts( array(
'type' => 'php',
), $atts );
return '<pre class="language-' . $atts['type'] . '"><code>' . $content . '</code></pre>';
}
add_shortcode('code', 'my_code_output');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment