Created
August 4, 2011 14:04
-
-
Save marcboivin/1125221 to your computer and use it in GitHub Desktop.
Super simple way to add HTML to WordPress Post
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 | |
/* | |
Usage: [html tag="div" class="calls1 calss2 class3" id="my_id"] ; This will create a <div class="calls1 calss2 class3" id="my_id"> to close use end=true to <div></div> use autoclose=true | |
[html tag="div" class="calls1 calss2 class3" id="my_id" end=true] ; Will do </div> keep the other param to make the code clearer | |
*/ | |
add_shortcode( 'html', 'simple_html_tag' ); | |
function simple_html_tag($atts){ | |
global $post; | |
$output = ''; | |
//Extrat le parametre $id et l'initialise | |
extract(shortcode_atts(array( | |
'tag' => '', | |
'class' => '', | |
'id' => '', | |
'end' => false, | |
'autoclose' => false | |
), $atts)); | |
if($end){ | |
$output .= '</'. $tag .'>'; | |
return $output; | |
} | |
$output .= '<'. $tag.' '; | |
if(!empty($class)) | |
$output .= 'class="' . $class . '" '; | |
if(!empty($id)) | |
$output .= 'id="'. $id . '"'; | |
$output .= '>'; | |
if($autoclose) | |
$output .= '</'. $tag .'>'; | |
return $output; | |
} | |
function disable_br(){ | |
remove_filter('the_content', 'wpautop'); | |
add_filter('the_content', 'enable_autop_wo_br'); | |
} | |
function enable_autop_wo_br($content){ | |
return wpautop($content, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment