• Resolved k.borisov

    (@kborisov)


    The AMP code entered in the description of the product category gets removed.
    The same code works in sandbox, or in the pages of the website.

    <button id="hide-button" on="tap:AMP.setState({message:!message})">Click</button>
    <p hidden [hidden]="message">Message</p>

    I’ve also tried with simpler things like on:tap.hide/show.

    The template of the page is built with AMP and every other aspect works.
    The problem is that we can’t include AMP code in the description field.
    This used to work before we made a major update – wordpress and plugins versions from the beginning of 2021 to the latest at the moment.

    I’ve disabled the woocommerce html sanitization, following the documentation. This is working – when I enable it the whole html gets removed.

    foreach ( array( 'pre_term_description' ) as $filter ) {
    	remove_filter( $filter, 'wp_filter_kses' );
    }
    
    foreach ( array( 'term_description' ) as $filter ) {
    	remove_filter( $filter, 'wp_kses_data' );
    }

    Thanks,
    Kamen

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Milind More

    (@milindmore22)

    Hello @kborisov

    Thank you for contacting us, As you are aware that the WordPress might be sanitizing the taxonomy description field (removing / striping) the code. this is not an AMP plugin issue.

    I will recommend adding the code using the woocommerce_archive_description action hook

    eg:

    add_action( 'woocommerce_archive_description', function() {
    	?>
    	<button id="hide-button" on="tap:AMP.setState({message:!message})">Click</button>
    	<p hidden [hidden]="message">Message</p>
    	<?php
    } );
    Thread Starter k.borisov

    (@kborisov)

    I need to add the code from the edit category page. I want to add some interactability to the page. The example I gave is just to easily test it.
    The content and the AMP components will be different for each category and an administrator should be able to change them without any theme customizations.

    As I mentioned, I’ve successfully turned off the HTML sanitization of those fields.
    I believe that WordPress detected the AMP syntaxis as invalid HTML code and clears it. Is there any way to disable it?

    Plugin Support Milind More

    (@milindmore22)

    Hello @kborisov

    it’s WooCommerce using wp_kses_post to remove the non-allowed HTML while displaying on front page.

    However here are steps you can follow to add custom HTML in description.

    1) Steps 1: Allow html category description use this plugin

    2) Steps 2 : Allow woocommerce to display description

    // remove WooCommernce archive description.
    remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
    remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
    
    // Add Custom WooCommernce archive description.
    add_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description_allow_html', 10 );
    add_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description_allow_html', 10 );
    
    if ( ! function_exists( 'woocommerce_taxonomy_archive_description_allow_html' ) ) {
    
    	/**
    	 * Show an archive description on taxonomy archives.
    	 */
    	function woocommerce_taxonomy_archive_description_allow_html() {
    		if ( is_product_taxonomy() && 0 === absint( get_query_var( 'paged' ) ) ) {
    			$term = get_queried_object();
    
    			if ( $term && ! empty( $term->description ) ) {
    				echo '<div class="term-description">' . $term->description . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    			}
    		}
    	}
    }
    Plugin Support Milind More

    (@milindmore22)

    @kborisov As we didn’t receive a response I’ll mark this as resolved. Feel free to open a new support topic if you require any further assistance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘AMP code is removed from product category page.’ is closed to new replies.