Created
January 8, 2013 04:12
-
-
Save zenman/4481080 to your computer and use it in GitHub Desktop.
Add div section within the_content() as a short code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Add div section within the content as a short code. | |
* | |
* This allows users to edit content in visual mode without stripping | |
* out necessary but hidden <div> tags. | |
* | |
* Example usages: | |
* [section]My Content[/section] = <div>My Content</div> | |
* [section width='6']My Content[/section] = <div class="col6">My Content</div> | |
* [section width='6' class='last']My Content[/section] = <div class="col6 last">My Content</div> | |
* [section class='my-class']My Content[/section] = <div class="my-class">My Content</div> | |
*/ | |
function create_section($atts,$content){ | |
extract(shortcode_atts(array( | |
'width' => '', | |
'class' => '' | |
), $atts)); | |
if($width || $class){ | |
$classes = ' class="'; | |
$classes .= ($width ? 'col'.$width : ''); | |
$classes .= ($width && $class ? ' ' : ''); | |
$classes .= $class.'" '; | |
} | |
$return_string = '<div'.$classes.'>'.do_shortcode($content).'</div>'; | |
return $return_string; | |
} | |
add_shortcode('section', 'create_section'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment