add_to_cart shortcode generates unnecessary newlines (1 post)

  1. bobbingwide
    Posted 3 years ago #

    As documented in http://herbmiller.me/2013/07/24/h2gd-part-28-more-battles-with-wpautop-generating-invalid-html/
    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


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic