Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #913510
    jbbaille2
    Participant

    Hi there!

    I would like to remove the <p> tags that wordpress puts automatically on my code (why? I am still wondering…). It happens especially on my product page (I use Woocomerce). I have tried the following solutions, without success:

    1) I got this code from you guys from another topic but didn’t work:
    // Remove wpautop in product pages
    // =============================================================================
    function remove_autop_for_product( $content ){
    // check for product post type
    ‘product’ === get_post_type() && remove_filter( ‘the_content’, ‘wpautop’ );
    return $content;
    }
    add_action( ‘init’, ‘remove_autop_for_product’, 999999 );
    // =============================================================================

    2) I added to function.php this code:
    remove_filter( ‘the_content’, ‘wpautop’ );
    remove_filter( ‘the_excerpt’, ‘wpautop’ );

    3) I tried the plugin disable wpautop

    4) Finally, I commented on the file “default-filter.php” the lines:
    filter( ‘the_content’, ‘wpautop’ ); and
    remove_filter( ‘the_excerpt’, ‘wpautop’ );

    Nothing works! All my plugins are disable except from cornerstone and woocommerce (otherwise, my product page would be disable).

    Everything is up-to-date.

    You are basically my only chance not to finish this day completely depressed! Hope you can help me…

    Cheers,

    JB

    #913511
    jbbaille2
    Participant
    This reply has been marked as private.
    #913514
    jbbaille2
    Participant

    I just noticed that those <p> tags appear when I put two <br> in a row

    #913824
    Lely
    Moderator

    Hello JB,

    Those p tags are controlled by woocommerce templates. Please check this thread for the fixed:https://community.theme.co/forums/topic/auto-p-tags-in-woocommerce/page/2/#post-841072

    Hope this helps.

    #913990
    jbbaille2
    Participant

    Hi Lely, thank you for your answer. I put the following code (which if from your link) in my function.php file:

    function woocommerce_product_archive_description() {
    if ( is_post_type_archive( ‘product’ ) && get_query_var( ‘paged’ ) == 0 ) {
    $shop_page = get_post( wc_get_page_id( ‘shop’ ) );
    if ( $shop_page ) {
    $description = wc_format_content( $shop_page->post_content );
    if ( $description ) {
    $tags = array(“<p>”, “</p>”, “<br>”);
    $description = str_replace($tags, “”, $description);
    echo ‘<div class=”page-description”>’ . wpautop($description) . ‘</div>’;
    }
    }
    }
    }

    It did remove the <p> tags, but it removed the <br> tags as well. So I tried the following code:

    function woocommerce_product_archive_description() {
    if ( is_post_type_archive( ‘product’ ) && get_query_var( ‘paged’ ) == 0 ) {
    $shop_page = get_post( wc_get_page_id( ‘shop’ ) );
    if ( $shop_page ) {
    $description = wc_format_content( $shop_page->post_content );
    if ( $description ) {
    $tags = array(“<p>”, “</p>”);
    $description = str_replace($tags, “”, $description);
    echo ‘<div class=”page-description”>’ . wpautop($description) . ‘</div>’;
    }
    }
    }
    }

    Strangely enough, the <br> are still removed… which I don’t want…

    #914407
    Rupok
    Member

    Hi there,

    Thanks for updating. The following code (that you mentioned below as well) should not remove <br> tag.

    function woocommerce_product_archive_description() {
        if (is_post_type_archive('product') && get_query_var('paged') == 0) {
            $shop_page = get_post(wc_get_page_id('shop'));
            if ($shop_page) {
                $description = wc_format_content($shop_page - > post_content);
                if ($description) {
                    $tags = array("<p>", "</p>");
                    $description = str_replace($tags, "", $description);
                    echo '<div class="page-description">'.wpautop($description).
                    '</div>';
                }
            }
        }
    }

    Let’s clear your cache and check again. Make sure you don’t have any duplicate anywhere else.

    Cheers!

    #978030
    jbbaille2
    Participant

    Sorry it gave me a parse error when I put this code into function.php, which I really don’t understand because it is the same code that I tried yesterday, and it did nothing…

    #978269
    Rad
    Moderator

    Hi there,

    In that case, it’s better if I can test it directly 🙂

    Would you mind providing your FTP login credentials in private reply as well?

    Thanks!

    #978284
    jbbaille2
    Participant
    This reply has been marked as private.
    #978546
    Lely
    Moderator

    Hello JB,

    I can see that you have added the code correctly. Attached is a screenshot of the code from your functions.php file. Can you confirm that this solved? Although I can see that your product page is displaying weird. The related product is out of place. Please check any customization that might be causing that. You can try removing each custom code and add it function by function or file by file to check where it is coming from.

    Hope this helps.

  • <script> jQuery(function($){ $("#no-reply-913510 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>