Jump to content

Change home link


gaminn

Recommended Posts

In your screen I see that you already changed it name and friendly url probably too? Last step is go to themes translation and there you must change Home to Products it is in International > Translations > Front > Office Trnslations > Your theme or Core > select language > click on Modify > go to Shop > Theme > Global.

  • Like 1
Link to comment
Share on other sites

Thanks. That's rather a hack. Hopefully the word "Home" is not used elsewhere in prestashop.

Anyway, I translated "Home" as "Products", but still it points to the homepage/index (./). How can I change the link of Home (or Products now for me) to the root category? 

Edited by gaminn (see edit history)
Link to comment
Share on other sites

Please have a look at my first post. I wanted to change "Home" (in the red circle) to "Products". That is possible via the translation hack. I also wanted to change the link "Home" (now "Products") points to. When I click it it gets me to the homepage of my store (./). I want to change the link to point to my root products category which is ./2-products .

EDIT:

Now I see the translation hack is not good. I also have other pages in my store (contact us, terms and conditions etc) where "Home" was also translated to "Products" which is obviously non sense.

To further explain what I want: My root category is Products, it contains sub-categories, e.g. Drives. When I browse my store's catalog, the path under the logo of my store say e.g. Home / Drives when I'm in Drives category. It never contains my root category "Products", instead it contains "Home" which, when clicked, makes you leave catalog, it points to the homepage. I would like the path to by like Products / Drives, or Home / Products/ Drives would also be possible.

Edited by gaminn (see edit history)
Link to comment
Share on other sites

@gaminn

To change the root category label and URL in your PrestaShop breadcrumbs, follow these steps:

Step 1:
In your PrestaShop installation, navigate to override/controllers/front/. (If these folders do not exist, create them.)
Inside this folder, create a new PHP file named FrontController.php if it does not already exist.


Step 2:
Paste the following code into the FrontController.php file:

 

<?php
class FrontController extends FrontControllerCore
{
    protected function getBreadcrumbLinks()
    {
        // Replace '2' with the desired category ID
        $categoryId = 2;

        // Load the category based on ID and current language
        $category = new Category($categoryId, $this->context->language->id);

        $breadcrumb = [];

        $breadcrumb['links'][] = [
            'title' => $category->name,
            'url' => $this->context->link->getCategoryLink($category),
        ];

        return $breadcrumb;
    }
}
?>

Step 3:
Go to Advanced Parameters > Performance in your PrestaShop admin panel and click Clear Cache.

Step 4:
Visit the front end to check the breadcrumb. Review the screenshot for reference if needed.

We hope this solution works for you!
 

Link to comment
Share on other sites

Thanks. This almost works, but the label should not change for pages like contact us, terms and conditions etc. It should only change for catalog (pages where user browses products available in the shop).

 

For contact us, T&C etc page, it should be like this: Home -> Contact Us , Home -> Terms and conditions

For products catalog, it should be like this Root category -> Child category 1 -> etc.... or this is also acceptable: Home -> Root category -> Child category 1 -> etc....

To be honest I'm wondering why prestashop omits the root category in the labels, it doesn't make any sense to display Home -> Child category 1 so you have no chance to get back to the root category and instead, if you click Home, it brings you to the homepage.

Link to comment
Share on other sites

@gaminn

Thank you for your reply. To meet your requirements, please update the code as follows:

<?php
class FrontController extends FrontControllerCore
{
    protected function getBreadcrumbLinks()
    {
        // Replace '2' with the desired category ID
        $categoryId = 2;

        // Load the category based on ID and the current language
        $category = new Category($categoryId, $this->context->language->id);

        $breadcrumb = [];

        // Check if the current page is a category, product, manufacturer, or search page
        if (in_array($this->php_self, ['category', 'product', 'manufacturer', 'search'])) {
            // Replace "Home" with the custom category link
            $breadcrumb['links'][] = [
                'title' => $category->name,
                'url' => $this->context->link->getCategoryLink($category),
            ];
        } else {
            // Default "Home" breadcrumb link for other pages, such as CMS pages
            $breadcrumb['links'][] = [
                'title' => $this->getTranslator()->trans('Home', [], 'Shop.Theme.Global'),
                'url' => $this->context->link->getPageLink('index', true),
            ];
        }

        return $breadcrumb;
    }
}
?>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...