1. Home
  2. Allow HTML in the product description

Allow HTML in the product description

Enable the HTML Editor

In order to enable Vendors to use HTML Markup in the product short and long description, the Marketplace Administrator must first enable the use of the HTML Editor by doing the following.

  1. Go to ‘WC Vendors > Settings > Forms > Product’ page
  2. Check or select ‘Use HTML’ like in the screenshot below and finally ‘Save Settings’

After changing this option, you will be able to use regularly used HTML tags like links, paragraph, divs and others but you may not be able to isnsert HTML elements like iframes.

Allowing iFrames in shop description.

In order to be able to use iFrames and other special HTML tags, you will need to enable by adding the following filter to functions.php file or as a mu-plugin.


function wcv_wpkses_post_html_tags( $tags, $context ) {
	if ( 'post' === $context ) {
		$tags['iframe'] = array(
			'src'             => true,
			'height'          => true,
			'width'           => true,
			'frameborder'     => true,
			'allowfullscreen' => true,
		);
	}

	return $tags;
}

add_filter( 'wp_kses_allowed_html', 'wcv_wpkses_post_html_tags', 10, 2 );

Once this code snippet is added to your active theme’s functions.php file, then Vendors should be able to add IFrame elements in the product descriptions and those iframes should be properly rendered when viewing the single product page where the iframe was added.

If there is another tag that is stripped out of the HTML when saved, then it can be added by simply adding to the $tags array below the last line of the $tags[‘iframe’] as follows:

// ELEMENT_NAME  Replace with any HTML element/tag name.
$tags['ELEMENT_NAME'] = array(
	// List of allowed attributes
	'attribute_name' => true, // true = allow attribute, false = do not allow attribute
);

Once the functions.php file is saved, all HTML code added to product descriptions should be properly saved and rendered in the product page.

filters

Updated on April 14, 2020

Was this article helpful?