Title: Clean Html code?
Last modified: December 21, 2021

---

# Clean Html code?

 *  Resolved [alexsina](https://wordpress.org/support/users/alexsina/)
 * (@alexsina)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/)
 * Hello,
 * There are usually lots of Html code for images when imported, for best match 
   theme style, we need take lots of time to improve every one.
 * Is it possible to clean image Html code in this way when importing:
 * `<img src="https://ae01.alicdn.com/kf/Hc79317d70ecb47a2961adc1420c1f5a4R.jpg"/
   >`
 * or, any short Code snippets way to achieve it?
 * Thanks
    -  This topic was modified 4 years, 5 months ago by [alexsina](https://wordpress.org/support/users/alexsina/).

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [kimvt1991](https://wordpress.org/support/users/kimvt1991/)
 * (@kimvt1991)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15190404)
 * Hello,
 * With the current version, you can achieve that by adding below PHP snippet:
 *     ```
       add_filter( 'the_editor_content', function ( $content ) {
       	$page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
       	global $pagenow;
       	if ( $pagenow === 'admin.php' && $page === 'woocommerce-alidropship-import-list' ) {
       		$content = strip_tags( $content, array(
       			'div',
       			'p',
       			'span',
       			'ul',
       			'ol',
       			'li',
       			'br',
       			'i',
       			'table',
       			'tr',
       			'td',
       			'tbody'
       		) );
       	}
   
       	return $content;
       } );
       ```
   
 * Best regards
 *  Thread Starter [alexsina](https://wordpress.org/support/users/alexsina/)
 * (@alexsina)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15191437)
 * Hello,
 * Thanks for the codes, but all of the images disappeared, and please check the
   screenshot:
 * [https://prnt.sc/246pv7u](https://prnt.sc/246pv7u)
 * Thanks
 *  [kimvt1991](https://wordpress.org/support/users/kimvt1991/)
 * (@kimvt1991)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15192682)
 * Sorry, I thought you wanted to remove all images from description.
    So you want
   all images to have only src attribute, right? Please replace the code above with
   this one:
 *     ```
       add_filter( 'the_editor_content', function ( $content ) {
       	$page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
       	global $pagenow;
       	if ( $pagenow === 'admin.php' && $page === 'woocommerce-alidropship-import-list' ) {
       		preg_match_all( '/<img([\s\S]*?)src="([\s\S]*?)" \/>/im', $content, $matches );
       		if ( count( $matches[0] ) ) {
       			foreach ( $matches[0] as $key => $img ) {
       				$content = str_replace( $img, '<img src="' . $matches[2][ $key ] . '"/>', $content );
       			}
       		}
       	}
   
       	return $content;
       } );
       ```
   
 *  Thread Starter [alexsina](https://wordpress.org/support/users/alexsina/)
 * (@alexsina)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15193074)
 * Yes, exactly, great thanks.
 * Is it possible to remove all of none useful codes, for example, the following
   one in img ?
 * > class=”detail-desc-decorate-image”
 * and make the text content to be clean too?
    I mean I just want the plain text
   content. Please check the screenshot to understand what I mean:
 * [https://prnt.sc/24ayx8p](https://prnt.sc/24ayx8p)
 * So that, it looks like as the following screenshot:
 * [https://prnt.sc/24azd4x](https://prnt.sc/24azd4x)
 * We speed lost of time to manually edit these HTML codes of every imported product,
   it will save our tons of time if you can help to achieve the purpose.
 * Thanks again.
 *  [kimvt1991](https://wordpress.org/support/users/kimvt1991/)
 * (@kimvt1991)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15193103)
 * Here you are:
 *     ```
       add_filter( 'the_editor_content', function ( $content ) {
       	$page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
       	global $pagenow;
       	if ( $pagenow === 'admin.php' && $page === 'woocommerce-alidropship-import-list' ) {
       		preg_match_all( '/<img([\s\S]*?)src="([\s\S]*?)" \/>/im', $content, $matches );
       		if ( count( $matches[0] ) ) {
       			foreach ( $matches[0] as $key => $img ) {
       				$content = str_replace( $img, '<img src="' . $matches[2][ $key ] . '"/>', $content );
       			}
       		}
       		$content = strip_tags( $content, array( 'img' ) );
       	}
   
       	return $content;
       } );
       ```
   
 *  Thread Starter [alexsina](https://wordpress.org/support/users/alexsina/)
 * (@alexsina)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15194579)
 * Great, it will be much great if you can improve in two points, and please check
   the screenshot:
 * [https://prnt.sc/24foe65](https://prnt.sc/24foe65)
 * 1# I mean, there is no <p> or <tr>, but still, there will be an empty line between
   every text content. can you remove the empty lines, otherwise, we need to remove
   them one by one.
 * 2# Is it possible to remove
 * > class=”detail-desc-decorate-image”
 * ? I do not know what is used for, but it seems no use here, right?
 * Thanks
 *  [kimvt1991](https://wordpress.org/support/users/kimvt1991/)
 * (@kimvt1991)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15227481)
 * #1 I will put a filter to description in the following updates so that it can
   be easier to manage.
 * #2 It already works like that, I tested it.
 * Again, I have to remind you that we are not allowed to support premium users 
   here. Your future topics in this forum will not be supported.
 * Best regards
 *  Thread Starter [alexsina](https://wordpress.org/support/users/alexsina/)
 * (@alexsina)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15228791)
 * Great.
 * Ok, I see. I was just used to post here for long time before, and I understand.
 * Have a nice day.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Clean Html code?’ is closed to new replies.

 * ![](https://ps.w.org/woo-alidropship/assets/icon-128x128.gif?rev=3080898)
 * [ALD - Dropshipping and Fulfillment for AliExpress and WooCommerce](https://wordpress.org/plugins/woo-alidropship/)
 * [Support Threads](https://wordpress.org/support/plugin/woo-alidropship/)
 * [Active Topics](https://wordpress.org/support/plugin/woo-alidropship/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woo-alidropship/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woo-alidropship/reviews/)

 * 8 replies
 * 2 participants
 * Last reply from: [alexsina](https://wordpress.org/support/users/alexsina/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/clean-html-code-2/#post-15228791)
 * Status: resolved