1

I have moved the product summary on the single product page using this:

add_action( 'woocommerce_single_product_summary', 'custom_the_content', 35 );

function custom_the_content() {
echo the_content();
}

Now I need to wrap the content in a div, so I tried

    echo '<div class="mydiv">' . the_content() . '</div>';

but this results in the content not being wrapped by the div, instead the div is empty and just added to the html, with the content below. How can I wrap the content into my div?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
sarah579
  • 35
  • 4
  • Use simply [`get_the_content()` Wordpress function](https://developer.wordpress.org/reference/functions/get_the_content/) instead like `echo '
    ' . get_the_content(). '
    ';`.
    – LoicTheAztec Sep 04 '20 at 09:12

1 Answers1

1

You need to use get_the_content(); instead of the_content(); if you want to echo it by yourself.

the_content() already does echo internally so you won't be able to wrap it.

If your page content contains data that should be processed by wp internal filters (like shortcodes) then you should use something like this:

ob_start();
the_content();
$content= ob_get_clean();
echo '<div class="mydiv">' . $content. '</div>';

More explanation: WordPress: difference between get_the_content() and the_content()

Diego
  • 1,610
  • 1
  • 14
  • 26
  • 1
    (Of course you’d be _able to_ wrap it - you just mustn’t use it in a string concatenation context then. `echo '
    ; the_content(); echo '
    ';` would still work perfectly fine here.)
    – CBroe Sep 04 '20 at 08:29