0

In my Magento site, I want to move Welcome element which shows after login to the start of the top.links.

Currently it is showing in the end after login.

Without login:

enter image description here

With login:

enter image description here

Without login screen is fine and I want it in the same manner, but after login, it shows Welcome text at the end, whereas I want it in the starting.

I tried to add float: left to .welcome <li> but then it leave a space in the end when user is not loggedIn, as below:

enter image description here

Default Magento Blank looks like this: enter image description here

Please help!

5
  • You can try solution mentioned in the below link magento.stackexchange.com/questions/247546/… Aug 4, 2020 at 14:08
  • Hi @LokeshNaik the solution given in that answer is to move the element, but I want to keep it in the same <ul> tag, but instead want to place it in the start of the list.
    – djmzfKnm
    Aug 4, 2020 at 17:55
  • By default, magento places the welcome text at the start of the list for both logged-in and non-logged in users. It seems in your theme the blocks under <referenceBlock name="top.links"> ... </referenceBlock> has been overridden which may have altered the default sort order. Aug 6, 2020 at 5:00
  • @LokeshNaik I think not, as Magento blank theme shows it in the middle, could you please check the screenshot I have attached in the question.
    – djmzfKnm
    Aug 7, 2020 at 7:28
  • Oh yes! I was checking in default magento setup with luma theme. Check the answer below. Aug 14, 2020 at 10:26

1 Answer 1

0

The default Magento\Theme\Block\Html\Header block which renders welcome text does not implement SortLinkInterface

You need to create a custom block which implements SortLinkInterface and pass the sortOrder as an argument to be able to sort it in comparison to other top links which implement the same interface.

Create below files in your module

app/code/Vendorname/Modulename/view/frontend/layout/default.xml

<?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="top.links">
            <block class="Vendorname\Modulename\Block\Html\Header" name="header" as="header" template="Magento_Theme::html/header.phtml">
                <arguments>
                    <argument name="show_part" xsi:type="string">welcome</argument>
                    <argument name="sortOrder" xsi:type="number">220</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

app/code/Vendorname/Modulename/Block/Html/Header.php

<?php

namespace Vendorname\Modulename\Block\Html;

use Magento\Customer\Block\Account\SortLinkInterface;

class Header extends \Magento\Framework\View\Element\Html\Link implements SortLinkInterface
{
    /**
     * Retrieve welcome text
     *
     * @return string
     */
    public function getWelcome()
    {
        if (empty($this->_data['welcome'])) {
            $this->_data['welcome'] = $this->_scopeConfig->getValue(
                'design/header/welcome',
                \Magento\Store\Model\ScopeInterface::SCOPE_STORE
            );
        }
        return __($this->_data['welcome']);
    }

    /**
     * {@inheritdoc}
     * @since 101.0.0
     */
    public function getSortOrder()
    {
        return $this->getData(self::SORT_ORDER);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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