How to move custom link right after logo in custom theme?
-
15-04-2021 - |
Pergunta
I have created custom link under
app\design\frontend\Myrwd\mytheme\Magento_Theme\layout\default.xml
<!-- location added in header -->
<referenceBlock name="header.links">
<block class="Magento\Framework\view\Element\Html\Link" name="custom-link" before="-">
<arguments>
<argument name="label" xsi:type="string" translate="true"> Custom Link </argument>
<argument name="path" xsi:type="string" translate="true"> customlink </argument>
</arguments>
</block>
</referenceBlock>
Now my custom link placed between customer link and minicart, how should place right after logo?
Workout :
In same path (app\design\frontend\Myrwd\mytheme\Magento_Theme\layout\default.xml)
I have added,
<move element="custom-link" destination="header-panel" after="logo" />
Its not working, how to solve the issue?
Solução
Replace this below code inside your default.xml file :
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="header.links">
<block class="Magento\Framework\view\Element\Html\Link" name="custom-link" before="-">
<arguments>
<argument name="label" xsi:type="string" translate="true"> Custom Link </argument>
<argument name="path" xsi:type="string" translate="true"> customlink </argument>
</arguments>
</block>
</referenceBlock>
<move element="custom-link" destination="header-wrapper" after="logo" />
</body>
</page>
Clean cache and check it.
Outras dicas
Try it :-
You can create custom container in header :-
<referenceContainer name="header-wrapper">
<container name="your-container-name" label="Header Top" htmlTag="div" htmlClass="your-header-top" after="logo">
</container>
</referenceContainer>
After Create container you can move your custom link in custom container :-
<move element="custom-link" destination="your-container-name" before="-" />
Try this,
<move element="custom-link" destination="header-wrapper" after="logo" />
you have a typo mistake in your move
tag
<move element="custom-link" destination="header-panel" after="logo" />
the destination
should be header.panel
<move element="custom-link" destination="header.panel" after="logo" />
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange