Truncate Brand Description on Single Product page

This topic has 6 replies, 3 voices, and was last updated 5 years, 6 months ago ago by Olga Barlow

  • Avatar: David Henry
    David Henry
    Participant
    June 5, 2018 at 18:54

    Hi Guys,

    I have this set up in the child theme but I cannot limit the Brand Description on the Single Product page to 40 charachters, this is what I need to alter:

    <?php echo $brand->description;?>

    It needs to be changed to something like this:

    <?php echo wp_trim_words( $brand->description(), 40, '...' ); ?>

    But what’s the correct php for this, any help would be greatly appriciated.

    David

    5 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    June 6, 2018 at 07:13

    Hello,

    Please try this code:
    <?php if (strlen($brand->description()) > 40) { echo substr($brand->description(),0,40).'...';} else { echo $brand->description(); } ?>

    Regards

    Avatar: David Henry
    David Henry
    Participant
    June 6, 2018 at 12:40

    Rose, your a star, you’ve gone one step further and by adding the condition.

    There was an error in the code so I’ve changed it to:

    <?php if (strlen($brand->description) > 145) { echo 
    substr($brand->description,0,145).'...';} else { echo $brand->description;
     } ?>

    I’ve taken out the () after description and it works brilliantly.

    Thanks again.
    David

    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    June 6, 2018 at 12:44

    You’re welcome!

    Regards

    Avatar: David Henry
    David Henry
    Participant
    October 25, 2018 at 19:05

    this stopped working after the update to xstore5, I’ve changed it to:

    <?php if (strlen($brand->description) > 145) { echo wp_specialchars_decode( substr($brand->description,0,245)).'...';} else { echo $brand->description; } ?>

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    October 26, 2018 at 15:30

    Hello,

    Ok, so does it work for you or you need any help from our side?

    Regards

  • Viewing 6 results - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.