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; ?>

Tags: magento code