1

I'm on Magento 2.1.6. The header links are rendered with this structure:

<ul class="header links">
  <li>...</li>
  <li>...</li>
  ...
</ul>

My HTML structure is like this:

enter image description here

How can I remove ul tag?? I do not require ul tag.

2 Answers 2

4

You can change Links.php at this location :- vendor/magento/framework/View/Element/Html

Probably on line no 76 remove the UL or change it to DIV

5
  • i did not find in ul tag,here not available ul tag Commented Jun 13, 2017 at 11:55
  • check in the end of file , " protected function _toHtml() { if (false != $this->getTemplate()) { return parent::_toHtml(); } $html = ''; if ($this->getLinks()) { $html = '<ul . ($this->hasCssClass() ? ' class="' . $this->escapeHtml( $this->getCssClass() ) . '"' : '') . '>'; foreach ($this->getLinks() as $link) { $html .= $this->renderLink($link); } $html .= '</ul>'; } return $html; } } " or search getLinks Commented Jun 13, 2017 at 12:15
  • it is working sorry i am open Link.php file Commented Jun 13, 2017 at 12:18
  • can i overite this file??how?? Commented Jun 13, 2017 at 12:18
  • Great ! I hope you got what you were looking for Commented Jun 13, 2017 at 12:18
2

I am extending the answer given by Manoj..

It is required to create a custom module, let us say Stack_Links, follow this link for the same Dev Doc

Then create di.xml file within \app\code\Stack\Links\etc directory of module as below:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Framework/ObjectManager/etc/config.xsd">     
    <preference for="Magento\Framework\View\Element\Html\Links" type="Stack\Links\Block\Links" />
</config>

Then Copy

\Magento\Framework\View\Element\Template\Links.php

file to

\app\code\Stack\Links\Block\Links.php

Then modify _toHtml() method according to requirement such as below to remove UL tag.

protected function _toHtml()
{
    if (false != $this->getTemplate()) {
        return parent::_toHtml();
    }

    $html = '';
    if ($this->getLinks()) {            
        foreach ($this->getLinks() as $link) {
            $html .= $this->renderLink($link);
        }            
    }

    return $html;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.