0

These code adds the full content of the product page and i cant seam to find a way to limit the amount of content to display. So when i add these code i get product page whit extremely long texts instead of a short description. I also cant use the short description for these since i have used that box for other information that is not relevant in the store page.

I have tried to add echo 'limit=50' but it don't work, i have also tried versus other codes but none seem to fix the problem

function extra_description() { 
        global $post;
        echo '<div itemprop="description">';
            echo apply_filters( 'the_content', $post->post_content );
        echo '</div>';
    }

add_action('woocommerce_after_shop_loop_item', 'extra_description', 1);

These code shows content to the products on the store page (Under the image and title for products) but these code displays all the content on the site. I would like to limit it to only 50-100 words.

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
SloZiga
  • 1
  • 1

1 Answers1

0

What about using the PHP function substr()? For example, instead of the line with echo apply_filters(), you do:

$content = apply_filters( 'the_content', $post->post_content );
$limit = 75;
$content = substr($content, 0, $limit);
echo $content;
Ewald
  • 46
  • 3
  • Thank you for your help, almost working just need a little more help. – SloZiga Feb 17 '19 at 18:31
  • Hello thank you for your help i have tried to add your code and it does limit the content but it also shows the actual HTML code or to be exact Divi code (from the Divi theme) https://i.stack.imgur.com/oxQuN.png i had to change it a little to $content = apply_filters( 'description', $post->post_content ); the code: $content = apply_filters( 'the_content', $post->post_content ); displayed all the products in a single grid box as seen in these photo below https://i.stack.imgur.com/vDJdL.png – SloZiga Feb 17 '19 at 19:10