Vince P
Vince P

Reputation: 1791

Magento - How to replace 'Home' in the breadcrumb?

I'm just wondering if anyone has had any experience in formatting the breadcrumb in Magento?

I would like to replace the link that currently displays the text 'HOME' with an image.

I thought it would be a simple case of replacing some text with a picture but it seems the 'HOME' text/link is dynamically created as this is all that is in the breadcrumbs.phtml:

<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
    <ul>
        <?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
            <li class="<?php echo $_crumbName ?>">
            <?php if($_crumbInfo['link']): ?>
                <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
            <?php elseif($_crumbInfo['last']): ?>
                <strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
            <?php else: ?>
                <?php echo $this->htmlEscape($_crumbInfo['label']) ?>
            <?php endif; ?>
            <?php if(!$_crumbInfo['last']): ?>
                <span>&gt;</span>
            <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
</div>
<?php endif; ?>

Upvotes: 2

Views: 13658

Answers (5)

Dan Sandland
Dan Sandland

Reputation: 7193

Edit your theme's breadcrumbs.phtml file:

/app/design/frontend/[YOUR_THEME]/default/template/page/html/breadcrumbs.phtml

If you want to replace the Home crumb with an image:

<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
    <li class="<?php echo $_crumbName ?>">
    <?php if($_crumbInfo['first']): ?>
        <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>">
            <img src="/your/image/path.png"/>
        </a>
    <?php elseif($_crumbInfo['link']): ?>
        <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>

If you want to remove the Home crumb entirely, which is what I needed:

<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
    <?php if ($_crumbInfo['first']) continue ?>
    <li class="<?php echo $_crumbName ?>">
    <?php if($_crumbInfo['link']): ?>

Upvotes: 0

user1553711
user1553711

Reputation: 141

No need to write any code for this,just using your translate file we can change "Home" in the breadcrumb.

For this :

goto your theme -> create locale directory-> create en_us directory -> create translate.csv .

In this just write below code

"Home","your choice".

Upvotes: 0

MGP
MGP

Reputation: 653

You can, in fact, hide that first "Home" from appear in your breadcrumbs without messing with CSS and keeping your HTML clean.

Just add the rule "!$_crumbInfo['first']" to your if conditions, just like:

<?php if ($crumbs && is_array($crumbs)): ?>
    <?php foreach ($crumbs as $_crumbName => $_crumbInfo): ?>
        <?php if ($_crumbInfo['link'] && !$_crumbInfo['first']): ?>
            <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
        <?php elseif ($_crumbInfo['last']): ?>
            <?php echo $this->htmlEscape($_crumbInfo['label']) ?>
        <?php elseif (!$_crumbInfo['first']): ?>
            <?php echo $this->htmlEscape($_crumbInfo['label']) ?>
        <?php else: ?>
        <?php endif; ?>
        <?php if (!$_crumbInfo['last'] && !$_crumbInfo['first']): ?>
            » 
        <?php endif; ?>
    <?php endforeach; ?>
<?php endif; ?>

Upvotes: 4

Joe Mastey
Joe Mastey

Reputation: 27119

Use CSS, this is a fight that isn't really worth it :) The 5 lines of CSS will take care of the issue much more easily than attempting to hack apart the breadcrumb renderers.

Upvotes: 1

shaune
shaune

Reputation: 2520

I think this is set in app/code/core/Mage/Cms/Block/Page.php. Look in the _prepareLayout() method (I am using magento 1.3, so this might be a little out of date).

I see you have a few options to update.

  1. Edit the file directly. (not my recommendation, but the fasted way)
  2. Override the class in your own module
  3. Create an entry your theme's translate.csv file. This is the way I like to update verbiage under normal situations, but it may not be your cup of tea. So in app/design/frontend/your_package/your_theme/locale/en_US/translate.csv you can put a new line that says "Home","" and then presto.
  4. Edit your css file instead of php/phtml files. If you are halfway experienced with css you can likely just set the text-indent to -2000em and set a background image.

Upvotes: 2

Related Questions