Removing Automatic Line Breaks <br> From Magento’s Product Descriptions

Geoff Jackson

Geoff Jackson (more commonly known by his online pseudonym zigojacko) is the founder of Design Haven and The Clubnet Group which hosts numerous agencies including the most widely recognised of them, Clubnet Digital, a full service digital marketing and creative design/development agency. He also has a personal blog but it doesn't get updated as much as he'd like.

You may also like...

Sponsored Links...

Subscribe to Design Haven UK

Enter your email address to subscribe and receive our new posts by email.

15 Responses

  1. Hi,

    Thank you for your post on the extra line breaks that Magento was putting into the product descriptions.

    It had been driving me slowly mad – and I couldn’t figure out where it was coming from.

    Thanks again!

    Richard

  2. Coen says:

    Thanks for explaining and now it works!

    The only different we had to make was in the code of the description and we placed the code lik:

    productAttribute($_product, $_product->getDescription(), ‘description’) ?>

    With the one you placed in your article the description did not show.

  3. Coen says:

    Btw. we did have one more thing implementing this. The styling of our old products is going wrong now because he does not load the extra space between p classes and most products are implemented that way.

    We are now looking how to make it work both ways.

    • Probably only a small tweak required to the CSS to make the paragraph blocks have a margin-bottom? For what it’s worth, in the latest versions of Magento, I don’t think this is an issue any longer.

  4. Wayne Austin says:

    Cheers Geoff. Did the trick for me on a clients site! Was a slightly different piece of code in Mage 1.9 but it was clear to just remove “nl2br”

  5. cosmin says:

    IT WORKS! Thank you very much.

  6. Thanks so much! 🙂 My next task is to try and remove the need to enter html tags in Description / Short description attribute fields. In Short Description I need every new line to appear as a new <li></li> in a <ul></ul> list. For Description I need to do exactly the same, but I also want to include a lump of text at the start that shouldn’t be affected (maybe wait two line breaks before starting the <ul>). Any idea where I might find info on how to do this?

    Thanks again for this post, was extremely helpful 🙂

     

    Kind Regards,

    Gideon

    • Hey Gideon, glad the post helped and thanks for taking the time to leave a comment.

      Is there any reason why you could not just enable the WYSIWYG editor and then click the bullet list to add your lists in the description fields (eradicating the need to manually add the HTML tags for each)?

      By modifying this in the theme template files, you could only wrap the entire WYSIWYG contents in specific markup which wouldn’t achieve the desired effect you’re after (every new line in the editor as an <li></li> within a <ul></ul>). The only way to achieve that would be to modify this after it is saved with JavaScript but it can become a bit messy.

      There’s loads of ways to insert a paragraph of text before your list though which won’t get changed. You could either insert it directly into the template file (theme/template/catalog/product/view/description.phtml) after <div class=”std”> so that it appears at the start of every product description although this means that you’d have to manually edit a template file to make any changes to it (shouldn’t really be done like this) or you could just add this text to a static block and then call the static block in from the same location in the template file or in the editor for each description. You could add it as a custom attribute and call it in before the product descriptions amongst other methods as well.

      Hope that helps.

  7. Thank you very much, very easy to understand and implement. Keep up the good work!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: