Shortcode insert div to content (editor)

Sometimes extra “div’s” are needed …
Insert div via shortcode. It’s easy !

Why would you want to insert div’s?
Standard WordPress wraps all the content in paragraphs ( you know those p tags) however now and then you want two columns or assign a class to a certain part of your content. Or maybe you want to split the page, there are of course different ways to go about, using this snippet is one of them.
[div id="ID" class="CLASS"]xxxx[/div]

Credits go to Neil, I’ve found it at  githhub

# For Functions.php
// DIV SHORTCODE. 
function createDiv($atts, $content = null) {
   extract(shortcode_atts(array(
      'id' => "",
      'class' => "",
   ), $atts));
return '






<div id="'. $id . '" class="'. $class . '" />' . $content . '</div>






';
}
add_shortcode('div', 'createDiv');

Leave a Reply