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
function createDiv($atts, $content = null) {
      'id' => "",
      'class' => "",
   ), $atts));
return '

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

add_shortcode('div', 'createDiv');

Leave a Reply