Skip to content

Instantly share code, notes, and snippets.

@bolderelements
Last active October 24, 2018 15:34
Show Gist options
  • Save bolderelements/3efc46a2de8c20c16570528fcf393fec to your computer and use it in GitHub Desktop.
Save bolderelements/3efc46a2de8c20c16570528fcf393fec to your computer and use it in GitHub Desktop.
Add <img> tag to WordPress data elements
/*
* Adds the <img> tag to allowed tags in fields sanitized using the wp_kses_data function.
*
* This particularly helps with adding images to Compare Table Features for individual products
*/
add_filter( 'wp_kses_allowed_html', 'my_kses_allowed_html_hook', 23, 2 );
function my_kses_allowed_html_hook( $allowed_tags, $context = null ){
if ( 'post' == $context && ! isset( $allowed_tags['img'] ) ) {
$allowed_tags['img'] = array(
'alt' => true,
'align' => true,
'border' => true,
'height' => true,
'src' => true,
'width' => true,
'class' => true,
'id' => true,
'style' => true,
'title' => true,
);
}
return $allowed_tags;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment