Skip to content

Instantly share code, notes, and snippets.

@marcboivin
Created August 4, 2011 14:04
Show Gist options
  • Save marcboivin/1125221 to your computer and use it in GitHub Desktop.
Save marcboivin/1125221 to your computer and use it in GitHub Desktop.
Super simple way to add HTML to WordPress Post
<?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