Skip to main content

How to remove <br /> added by magento.

In case you're wondering why your product description is all spaced out, then that's because magento is adding automatic line breaks into the content description area...

To get rid of it... look for

nl2br

specifically in description.phtml you'll see

<div class="std">
    <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), nl2br($this->getProduct()->getDescription()), 'description') ?>
</div>

it should look like this after you take the nl2br out:

<div class="std">
    <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), ($this->getProduct()->getDescription()), 'description') ?>
</div>

Noticed that Magento 1.4.1 has this structured a little differently. It has the line breaks already turned off--doesn't include nl2br, and rather uses a built in WYSIWYG editor for the description section.

If you want to go back to the old way of line breaks, and don't want to use the WYSIWYG editor. E.g. you have a site that already has it's products input the old way (in this case, the formatting would be lost, so you'd have to redo all descriptions using WYSIWYG... and if you have a lot of products this can take very long)

anyhow...

I copied description.phtml from the base directory into my custom template one (base always has the latest version template files--which get changed often when upgrading)

app/design/frontend/base/default/template/catalog/product/view/description.phtml

before

<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
    <h2><?php echo $this->__('Details') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
    </div>
<?php endif; ?>

after

<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
    <h2><?php echo $this->__('Details') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), nl2br($_description), 'description') ?>
    </div>
<?php endif; ?>

Comments

Thanks for the tip...

Thanks for the tip...

very useful!

thanks for this useful post! i fix the problem,it looks pretty good now!
thanks again!

It simply doesn't work! I

It simply doesn't work! I tried to remove that part of the code and it is still the same. Still having 's in every description!

Problem Fixed! (Note: DIDN'T

Problem Fixed! (Note: DIDN'T CHANGED ANYTHING IN THE .PHP FILE or ANYWHERE ELSE AS BEING SUGGESTED IN MANY PLACES)

Went to in Admin

In Catalog>Attributes>Manage Attributes look for "Description" and "Short Description" attributes. Once in look for "Enable WYSIWYG" option and select "Yes".

That's it!

(The above suggestions with the code editing, etc. may work if you do not have any attributes installed. If you do, don't bother.)

If that removes the generated

If that removes the auto-generated line breaks in code while inputing custom/advanced HTML, then that would work.

However, with your suggestion, enabling the WYSIWYG editor, logic would state that would only make things worse--i.e. one would turn off the the WYSIWYG editor to do hand coded (custom) HTML, not turn it on. WYSIWYG does exactly what this suggestion is trying to prevent, it automatically ads HTML line breaks/paragraphs during carriage returns.

btw, you have to make sure

btw, you have to make sure you're editing the currently used theme.

Thanks, works perfectly!

Thanks, works perfectly!

Thank you mang. Wondering

Thank you mang. Wondering wtf the deal was with that. Thank you!!!

Thank you so much! this will

Thank you so much! this will save me hours if not days, removing formating.

Godspeed ;)

Thank you! My product view

Thank you! My product view description looks so awesome now! http://magazento.com/english/magento-ext/magazento-extensions/magazento-anyslider

Very Good

Very Good article

Thanks
JeevanSathi

really thanks for the help

really thanks for the help

Works perfectly!

Works perfectly!

This is an excellent post. I

This is an excellent post. I really appreciate with you. I enjoyed the post. Thanks for sharing.

Very usefull!

Very usefull!

Hi, I was dealing with this

Hi, I was dealing with this problem as well, but was able to resolve the problem after a while. Good post though

A better way would be to add

A better way would be to add an attribute to every attribute set and placed just under the Description text box, called IsHTMLDescription.

Then you can declare if the description is simply text, or html code.

Inside description.phtml ive got

<?php

        $is_html_desc

= $this->getProduct()->getAttributeText('is_html_description');
        if (
$is_html_desc == "Yes")
            echo
$this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description');
        else
            echo
nl2br($this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description'));
       
?>

Post new comment

The content of this field is kept private and will not be shown publicly.