• Resolved alexsina

    (@alexsina)


    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.
Viewing 8 replies - 1 through 8 (of 8 total)
  • 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

    (@alexsina)

    Hello,

    Thanks for the codes, but all of the images disappeared, and please check the screenshot:

    https://prnt.sc/246pv7u

    Thanks

    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

    (@alexsina)

    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

    So that, it looks like as the following screenshot:

    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.

    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

    (@alexsina)

    Great, it will be much great if you can improve in two points, and please check the screenshot:

    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

    #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

    (@alexsina)

    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.