Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress HTML tags shortcode. So you may add HTML to escaped form fields values :)
<?php
/**
* HTML tags shortcode
*
* Usage: [html tag="span" class="myClass" id="firstSpan"]Lorem ipsum[html tag='br']dolor sit amet[/html]
*/
function html_tag_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
'tag' => 'div',
'id' => '',
'class' => '',
'href' => '',
'src' => '',
'alt' => '',
'name' => '',
'type' => '',
'value' => '',
'style' => '',
), $atts, 'html' ) );
$single = array( 'img', 'br', 'input' );
if ( in_array( $tag, $single ) ) {
$return = '<' . esc_attr( $tag ) .
( $id ? ' id="' . esc_attr( $id ) . '"' : '' ) .
( $class ? ' class="' . esc_attr( $class ) . '"' : '' ) .
( $src ? ' src="' . esc_attr( $src ) . '"' : '' ) .
( $alt ? ' alt="' . esc_attr( $alt ) . '"' : ( $src ? ' alt=""' : '' ) ) .
( $name ? ' name="' . esc_attr( $name ) . '"' : '' ) .
( $type ? ' type="' . esc_attr( $type ) . '"' : '' ) .
( $value ? ' value="' . esc_attr( $value ) . '"' : '' ) .
( $style ? ' style="' . esc_attr( $style ) . '"' : '' ) .
' />';
}
else {
$return = '<' . esc_attr( $tag ) .
( $id ? ' id="' . esc_attr( $id ) . '"' : '' ) .
( $class ? ' class="' . esc_attr( $class ) . '"' : '' ) .
( $href ? ' href="' . esc_attr( $href ) . '"' : '' ) .
( $style ? ' style="' . esc_attr( $style ) . '"' : '' ) .
'>' . do_shortcode( $content ) . '</' . esc_attr( $tag ) . '>';
}
return $return;
}
add_shortcode( 'html', 'html_tag_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.