A client recently asked if it was possible to remove the welcome message that was appearing by default at the top of a Magento website she was building.

Here's how Magento renders the default home page using the popular Porto theme:

Magento's default top menu
[Fig.1 - Magento's default top menu including the welcome message]

Please forgive the garish colors - I didn't chose them! Anyway, take a close look at the extreme top menu. There are 4 links:

  • Default Welcome MSG!
  • Contact Us
  • Sign In
  • Create an Account

She wanted to get rid of the 'Default Welcome MSG!' link.

I was eager to help but I soon learned that customizing big CMS frameworks like Magento can be worse than simply building your own!

How to Remove the Default Welcome Message

Let's cut directly to the end-lesson for now: one way to remove the welcome greeting is to modify a template in: vendor/magento/module-theme/view/frontend/templates/html/header.phtml

This is how the header.phtml file looks, by default:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @var \Magento\Theme\Block\Html\Header $block
 */
$welcomeMessage = $block->getWelcome();
?>
<?php if ($block->getShowPart() == 'welcome') : ?>
    <li class="greet welcome" data-bind="scope: 'customer'">
        <!-- ko if: customer().fullname  -->
        <span class="logged-in"
              data-bind="text: new String('<?= $block->escapeHtml(__('Welcome, %1!', '%1')) ?>').replace('%1', customer().fullname)">
        </span>
        <!-- /ko -->
        <!-- ko ifnot: customer().fullname  -->
        <span class="not-logged-in" data-bind='html:"<?= $block->escapeHtml($welcomeMessage) ?>"'></span>
        <?= $block->getBlockHtml('header.additional') ?>
        <!-- /ko -->
    </li>
    <script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "customer": {
                        "component": "Magento_Customer/js/view/customer"
                    }
                }
            }
        }
    }
    </script>
<?php elseif ($block->getShowPart() == 'other') :?>
    <?= $block->getChildHtml() ?>
<?php endif ?>

This template helps render the <header> section of Magento's default home page.

There's this strange commented thing that looks like a conditional in the first list item:

        <!-- ko if: customer().fullname  -->
        <span class="logged-in"
              data-bind="text: new String('<?= $block->escapeHtml(__('Welcome, %1!', '%1')) ?>').replace('%1', customer().fullname)">
        </span>
        <!-- /ko -->
        <!-- ko ifnot: customer().fullname  -->
        <span class="not-logged-in" data-bind='html:"<?= $block->escapeHtml($welcomeMessage) ?>"'></span>
        <?= $block->getBlockHtml('header.additional') ?>
        <!-- /ko -->

That thing that says: ko if: really is a conditional. You can even see that there's an if not clause in there too. This conditional is checking to see if the user in this session is logged-in. If so, render a Welcome Username message.

If the user is not logged-in render the $welcomeMessage string.

The $welcomeMessage string was created right at the top of the header.phtml file using the $block->getWelcome() method.

So, one quick way to remove the welcome message from Magento's top menu is to comment out the span that renders that $welcomeMessage string. Here's how you might do it:

Find the <span> element right after the ko ifnot: conditional in the first <li> element and comment it out like this:

        <!-- ko ifnot: customer().fullname  -->
        <!-- <span class="not-logged-in" data-bind='html:"<?= $block->escapeHtml($welcomeMessage) ?>"'></span> -->
        <?= $block->getBlockHtml('header.additional') ?>
        <!-- /ko -->

That will remove the welcome message for the home page yet still allow the welcome message to appear for a logged-in user. If you want to remove that message as well, then comment-out the corresponding <span> in the ko if conditional.

All of this allows any other additional header elements to still appear if you've created them.

Clear Cache to See the Results

Remember to clear the cache to see the results immediately. At the root of your Magento installation do this:

php bin/magento c:c

For more on this subject see: Magento: Clearing the Cache

Anyway, that should do the trick. Go ahead and refresh your browser.

Conclusion

There may be various reasons why you might want to get rid of the welcome text in the topmost navigation menu of your Magento app. Whatever the reason may be, with a quick edit you can remove it.