Support » Plugin: WooCommerce » add_to_cart shortcode generates unnecessary newlines

  • As documented in
    I have determined that the HTML generated by the [add_to_cart] shortcode may be post processed by the wpautop() filter function leading to invalid HTML and a subsequent poor user experience.

    There is a very simple workaround to this problem. Just remove the blank lines from the code in product_add_to_cart()

    <p class="product woocommerce" style="<?php echo $atts['style']; ?>">
    				<?php echo $product->get_price_html(); ?>
    				<?php woocommerce_template_loop_add_to_cart(); ?>

    also remove some of the blank lines from /templates/loop/add-to-cart.php

    This will prevent wpautop() from adding unwanted /p and br tags if it happens to be run AFTER shortcode expansion

  • The topic ‘add_to_cart shortcode generates unnecessary newlines’ is closed to new replies.