X

Add div element shortcode including class

Just a simple shortcode that will let you add a div using shortcode to your posts and pages. Add this snippet to the functions.php of your WordPress theme and within any post you can write the following shortcode to include a <div class="my_class"></div> within your post. [div class="my_class"]content[/div] comes in handy if you need to do something custom on a post by post basis.


Code Snippet:


function div_html($atts, $content = null) {

extract( shortcode_atts( array(
'class' => '',
), $atts ) );

$class = $class ? '' class=\''$class\'''' : NULL;

return “<div$class>$content</div>'';
}
add_shortcode('div', 'div_html');

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!