Skip to content

Relative custom URL breaks when Magento store code is included in URLs #376

@Kashyap1999

Description

@Kashyap1999

Description:

When adding a Custom URL menu item, internal links are not working as expected.

If you enter an internal path like ‘/contact’ or ‘contact’ (as per screenshot-1), the generated menu link does not include the store’s base URL (see screenshot-2). This causes broken links when Magento is configured to include store codes in URLs.

For example, if you have two stores:
Store A: https://example.com/ (default)
Store B: https://example.com/storeB

Adding a Custom URL with ‘/contact’ will always render as ‘/contact’ instead of including the correct store code.
• On Store A → resolves as https://example.com/contact (works)
• On Store B → resolves as https://example.com/contact instead of https://example.com/storeB/contact (broken)

Only full external URLs (e.g. https://google.com) are rendered correctly.

Screenshot-1

Image

Screenshot-2

Image

Steps to Reproduce:

  1. Take a multi-store shop with snowdog/module-menu.
  2. Go to the Stores > Configuration > General > Web > Url Options, and enable “Add Store Code to URLs” configuration. (see screenshot-3)
  3. Now, Go to Admin > Content > Menus.
  4. Add a new Custom URL node.
  5. Enter /contact (or contact) as the URL.
  6. Save and check the frontend.
  7. Inspect the generated HTML.

Screenshot-3

Image

Expected Result:

The internal URL should be resolved with the store base URL, e.g.
<a href="https://example.com/contact">Contact Us</a>

As per screenshot-2, category url is generated with the base url same as custom url if not external link than it should be generate with the base url.

Actual Result:

Custom Url is without base url:
<a href="/contact">Contact Us</a>

Additional Information:

Block file: snowdog/module-menu/Block/NodeType/CustomUrl.php
Method getHtml() already checks for external vs internal URLs, but it outputs a full <a> tag, not just the resolved URL.

Screenshot-4

Image

Template file:
snowdog/module-menu/view/frontend/templates/menu/node_type/custom_url.phtml

The template defines its own <a> tag and calls $block->getContent() directly, which bypasses the internal/external check.

Screenshot-5

Image

Suggested Fix:
It’s seems the getHtml method is not called in the template files and it is return full html So we have to add new method to return the resolved URL only instead of html, e.g. (as screenshot-6).

Screenshot-6

Image

Then update the template to use this method instead of getContent():

Screenshot-7

Image

Need to update all custom_url.phtml from the module. Like,

hyva-topmenu-mobile: snowdog/module-menu/view/frontend/templates/hyva-topmenu-mobile/menu/node_type/custom_url.phtml

hyva-topmenu-desktop: snowdog/module-menu/view/frontend/templates/hyva-topmenu-desktop/menu/node_type/custom_url.phtml

hyva-menu-footer: snowdog/module-menu/view/frontend/templates/hyva-menu-footer/menu/node_type/custom_url.phtml

This ensures Internal URLs are automatically resolved with the correct store base URL.
External URLs are rendered as-is. And behavior is consistent across all store views.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions