How to Customise Header for guest and logged in user in magento2 programmatically?Magento 2 Luma Checkout Problem with logged in UsersAdded header link shows a second logout link next to itNo content is displaying on the main content areaHow to customise header template in magento 2Magento 2 - Error importing sample dataHow to Customize Magento 2 header layout with luma themeMagento2 change Luma header templateHow to add a background image to header content?How to add back to top button in Magento 2?No products on site after backup/restore database from one server to another

How to apply the changes to my `.zshrc` file after edit?

What is this spacecraft tethered to another spacecraft in LEO (vintage)

What is the most common end of life issue for a car?

Why do planes need a roll motion?

Suggestions for protecting jeans from saddle clamp bolt

Converting 8V AC to 8V DC - bridge rectifier gets very hot while idling

Japanese reading of an integer

Finding minimum time for vehicle to reach to its destination

Is there an antonym for "spicy" or "hot" regarding food (NOT "seasoned" but "spicy")?

Why isn't there any 9.5 digit multimeter or higher?

Examples of simultaneous independent breakthroughs

Word for showing a small part of something briefly to hint to its existence or beauty without fully uncovering it

What are the different qualities of the intervals?

Unethical behavior : should I report it?

Send a single HTML email from Thunderbird, overriding the default "plain text" setting

Could the rotation of a black hole cause other planets to rotate?

What do I do with a party that is much stronger than their level?

How many oliphaunts died in all of the Lord of the Rings battles?

Pointwise convergence of uniformly continuous functions to zero, but not uniformly

Why does Canada require mandatory bilingualism in all government posts?

If a 2019 UA artificer has the Repeating Shot infusion on two hand crossbows, can they use two-weapon fighting?

Are the named pipe created by `mknod` and the FIFO created by `mkfifo` equivalent?

Why is drive/partition number still used?

Vertical tennis ball into fancy new enumerate



How to Customise Header for guest and logged in user in magento2 programmatically?


Magento 2 Luma Checkout Problem with logged in UsersAdded header link shows a second logout link next to itNo content is displaying on the main content areaHow to customise header template in magento 2Magento 2 - Error importing sample dataHow to Customize Magento 2 header layout with luma themeMagento2 change Luma header templateHow to add a background image to header content?How to add back to top button in Magento 2?No products on site after backup/restore database from one server to another






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















enter image description hereI want different top header section for guest and login user.




Guest user header option



"Hi Guest" + sign-in option



Login user header option



"Hi [User Name]"




How do I perform it programmatically?










share|improve this question
























  • Are you using default magento 2 luma theme? And what is version of your magento?

    – Sweety Masmiya
    Jul 18 at 4:28











  • yes and using magento 2.3.2 with sample data

    – Naiwrita09
    Jul 18 at 4:35

















0















enter image description hereI want different top header section for guest and login user.




Guest user header option



"Hi Guest" + sign-in option



Login user header option



"Hi [User Name]"




How do I perform it programmatically?










share|improve this question
























  • Are you using default magento 2 luma theme? And what is version of your magento?

    – Sweety Masmiya
    Jul 18 at 4:28











  • yes and using magento 2.3.2 with sample data

    – Naiwrita09
    Jul 18 at 4:35













0












0








0








enter image description hereI want different top header section for guest and login user.




Guest user header option



"Hi Guest" + sign-in option



Login user header option



"Hi [User Name]"




How do I perform it programmatically?










share|improve this question
















enter image description hereI want different top header section for guest and login user.




Guest user header option



"Hi Guest" + sign-in option



Login user header option



"Hi [User Name]"




How do I perform it programmatically?







luma-theme magento2.3.2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 19 at 6:00









Teja Bhagavan Kollepara

3,0264 gold badges21 silver badges51 bronze badges




3,0264 gold badges21 silver badges51 bronze badges










asked Jul 18 at 4:03









Naiwrita09Naiwrita09

268 bronze badges




268 bronze badges












  • Are you using default magento 2 luma theme? And what is version of your magento?

    – Sweety Masmiya
    Jul 18 at 4:28











  • yes and using magento 2.3.2 with sample data

    – Naiwrita09
    Jul 18 at 4:35

















  • Are you using default magento 2 luma theme? And what is version of your magento?

    – Sweety Masmiya
    Jul 18 at 4:28











  • yes and using magento 2.3.2 with sample data

    – Naiwrita09
    Jul 18 at 4:35
















Are you using default magento 2 luma theme? And what is version of your magento?

– Sweety Masmiya
Jul 18 at 4:28





Are you using default magento 2 luma theme? And what is version of your magento?

– Sweety Masmiya
Jul 18 at 4:28













yes and using magento 2.3.2 with sample data

– Naiwrita09
Jul 18 at 4:35





yes and using magento 2.3.2 with sample data

– Naiwrita09
Jul 18 at 4:35










2 Answers
2






active

oldest

votes


















1














You could achieve this requirement using a Plugin.



File - VendorModuleetcdi.xml



<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoThemeBlockHtmlHeader" type="VendorModuleBlockHtmlMyCustomHeader" />
</config>


File - VendorModuleBlockHtmlMyCustomHeader.php



<?php

namespace VendorModuleBlockHtml;


class MyCustomHeader extends MagentoThemeBlockHtmlHeader

protected $_template = 'Magento_Theme::html/header.phtml';
protected $_customerSession ;

public function __construct(MagentoCustomerModelSession $customerSession, MagentoFrameworkViewElementTemplateContext $context, array $data = [])

$this->_customerSession = $customerSession ;

parent::__construct($context, $data);



/**
* Custom Logic For Welcome Text
*
* @return string
*/
public function getWelcome()

if($this->_customerSession->isLoggedIn())
return parent::getWelcome();

else
return __('Hi Guest!');








share|improve this answer























  • Thank you it worked.

    – Naiwrita09
    Jul 19 at 4:05











  • Sir I have added an image. I want to know how to change the "Myaccount" to logged in user name?

    – Naiwrita09
    Jul 19 at 6:00


















0















Actual file path vendor/magento/module-theme/view/frontend/templates/html/header.phtml



Override header.phtml file app/design/frontend/vendore/theme/Magento_Theme/templates/html/header.phtml




After that change



$welcomeMessage = $block->getWelcome();


to



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
$welcomeMessage = $block->getWelcome();

else
$welcomeMessage = 'Hi Guest!';



sign-in option automatically remove for login customer.






share|improve this answer

























  • is this feasible while designing any other website using magento

    – Naiwrita09
    Jul 18 at 4:49











  • Can you please elaborate your question?

    – Sweety Masmiya
    Jul 18 at 4:51











  • Suppose I am designing a website using magento 2 then will this change in code work for the same task

    – Naiwrita09
    Jul 18 at 4:53











  • If you will create another website with Magento then also this code is usable for you.

    – Sweety Masmiya
    Jul 18 at 4:56











  • Ok thank you. and if I use the other theme and not luna?

    – Naiwrita09
    Jul 18 at 5:11













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282453%2fhow-to-customise-header-for-guest-and-logged-in-user-in-magento2-programmaticall%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You could achieve this requirement using a Plugin.



File - VendorModuleetcdi.xml



<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoThemeBlockHtmlHeader" type="VendorModuleBlockHtmlMyCustomHeader" />
</config>


File - VendorModuleBlockHtmlMyCustomHeader.php



<?php

namespace VendorModuleBlockHtml;


class MyCustomHeader extends MagentoThemeBlockHtmlHeader

protected $_template = 'Magento_Theme::html/header.phtml';
protected $_customerSession ;

public function __construct(MagentoCustomerModelSession $customerSession, MagentoFrameworkViewElementTemplateContext $context, array $data = [])

$this->_customerSession = $customerSession ;

parent::__construct($context, $data);



/**
* Custom Logic For Welcome Text
*
* @return string
*/
public function getWelcome()

if($this->_customerSession->isLoggedIn())
return parent::getWelcome();

else
return __('Hi Guest!');








share|improve this answer























  • Thank you it worked.

    – Naiwrita09
    Jul 19 at 4:05











  • Sir I have added an image. I want to know how to change the "Myaccount" to logged in user name?

    – Naiwrita09
    Jul 19 at 6:00















1














You could achieve this requirement using a Plugin.



File - VendorModuleetcdi.xml



<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoThemeBlockHtmlHeader" type="VendorModuleBlockHtmlMyCustomHeader" />
</config>


File - VendorModuleBlockHtmlMyCustomHeader.php



<?php

namespace VendorModuleBlockHtml;


class MyCustomHeader extends MagentoThemeBlockHtmlHeader

protected $_template = 'Magento_Theme::html/header.phtml';
protected $_customerSession ;

public function __construct(MagentoCustomerModelSession $customerSession, MagentoFrameworkViewElementTemplateContext $context, array $data = [])

$this->_customerSession = $customerSession ;

parent::__construct($context, $data);



/**
* Custom Logic For Welcome Text
*
* @return string
*/
public function getWelcome()

if($this->_customerSession->isLoggedIn())
return parent::getWelcome();

else
return __('Hi Guest!');








share|improve this answer























  • Thank you it worked.

    – Naiwrita09
    Jul 19 at 4:05











  • Sir I have added an image. I want to know how to change the "Myaccount" to logged in user name?

    – Naiwrita09
    Jul 19 at 6:00













1












1








1







You could achieve this requirement using a Plugin.



File - VendorModuleetcdi.xml



<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoThemeBlockHtmlHeader" type="VendorModuleBlockHtmlMyCustomHeader" />
</config>


File - VendorModuleBlockHtmlMyCustomHeader.php



<?php

namespace VendorModuleBlockHtml;


class MyCustomHeader extends MagentoThemeBlockHtmlHeader

protected $_template = 'Magento_Theme::html/header.phtml';
protected $_customerSession ;

public function __construct(MagentoCustomerModelSession $customerSession, MagentoFrameworkViewElementTemplateContext $context, array $data = [])

$this->_customerSession = $customerSession ;

parent::__construct($context, $data);



/**
* Custom Logic For Welcome Text
*
* @return string
*/
public function getWelcome()

if($this->_customerSession->isLoggedIn())
return parent::getWelcome();

else
return __('Hi Guest!');








share|improve this answer













You could achieve this requirement using a Plugin.



File - VendorModuleetcdi.xml



<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoThemeBlockHtmlHeader" type="VendorModuleBlockHtmlMyCustomHeader" />
</config>


File - VendorModuleBlockHtmlMyCustomHeader.php



<?php

namespace VendorModuleBlockHtml;


class MyCustomHeader extends MagentoThemeBlockHtmlHeader

protected $_template = 'Magento_Theme::html/header.phtml';
protected $_customerSession ;

public function __construct(MagentoCustomerModelSession $customerSession, MagentoFrameworkViewElementTemplateContext $context, array $data = [])

$this->_customerSession = $customerSession ;

parent::__construct($context, $data);



/**
* Custom Logic For Welcome Text
*
* @return string
*/
public function getWelcome()

if($this->_customerSession->isLoggedIn())
return parent::getWelcome();

else
return __('Hi Guest!');









share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 18 at 19:57









Sharath KumarSharath Kumar

3461 silver badge10 bronze badges




3461 silver badge10 bronze badges












  • Thank you it worked.

    – Naiwrita09
    Jul 19 at 4:05











  • Sir I have added an image. I want to know how to change the "Myaccount" to logged in user name?

    – Naiwrita09
    Jul 19 at 6:00

















  • Thank you it worked.

    – Naiwrita09
    Jul 19 at 4:05











  • Sir I have added an image. I want to know how to change the "Myaccount" to logged in user name?

    – Naiwrita09
    Jul 19 at 6:00
















Thank you it worked.

– Naiwrita09
Jul 19 at 4:05





Thank you it worked.

– Naiwrita09
Jul 19 at 4:05













Sir I have added an image. I want to know how to change the "Myaccount" to logged in user name?

– Naiwrita09
Jul 19 at 6:00





Sir I have added an image. I want to know how to change the "Myaccount" to logged in user name?

– Naiwrita09
Jul 19 at 6:00













0















Actual file path vendor/magento/module-theme/view/frontend/templates/html/header.phtml



Override header.phtml file app/design/frontend/vendore/theme/Magento_Theme/templates/html/header.phtml




After that change



$welcomeMessage = $block->getWelcome();


to



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
$welcomeMessage = $block->getWelcome();

else
$welcomeMessage = 'Hi Guest!';



sign-in option automatically remove for login customer.






share|improve this answer

























  • is this feasible while designing any other website using magento

    – Naiwrita09
    Jul 18 at 4:49











  • Can you please elaborate your question?

    – Sweety Masmiya
    Jul 18 at 4:51











  • Suppose I am designing a website using magento 2 then will this change in code work for the same task

    – Naiwrita09
    Jul 18 at 4:53











  • If you will create another website with Magento then also this code is usable for you.

    – Sweety Masmiya
    Jul 18 at 4:56











  • Ok thank you. and if I use the other theme and not luna?

    – Naiwrita09
    Jul 18 at 5:11















0















Actual file path vendor/magento/module-theme/view/frontend/templates/html/header.phtml



Override header.phtml file app/design/frontend/vendore/theme/Magento_Theme/templates/html/header.phtml




After that change



$welcomeMessage = $block->getWelcome();


to



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
$welcomeMessage = $block->getWelcome();

else
$welcomeMessage = 'Hi Guest!';



sign-in option automatically remove for login customer.






share|improve this answer

























  • is this feasible while designing any other website using magento

    – Naiwrita09
    Jul 18 at 4:49











  • Can you please elaborate your question?

    – Sweety Masmiya
    Jul 18 at 4:51











  • Suppose I am designing a website using magento 2 then will this change in code work for the same task

    – Naiwrita09
    Jul 18 at 4:53











  • If you will create another website with Magento then also this code is usable for you.

    – Sweety Masmiya
    Jul 18 at 4:56











  • Ok thank you. and if I use the other theme and not luna?

    – Naiwrita09
    Jul 18 at 5:11













0












0








0








Actual file path vendor/magento/module-theme/view/frontend/templates/html/header.phtml



Override header.phtml file app/design/frontend/vendore/theme/Magento_Theme/templates/html/header.phtml




After that change



$welcomeMessage = $block->getWelcome();


to



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
$welcomeMessage = $block->getWelcome();

else
$welcomeMessage = 'Hi Guest!';



sign-in option automatically remove for login customer.






share|improve this answer
















Actual file path vendor/magento/module-theme/view/frontend/templates/html/header.phtml



Override header.phtml file app/design/frontend/vendore/theme/Magento_Theme/templates/html/header.phtml




After that change



$welcomeMessage = $block->getWelcome();


to



$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$customerSession = $objectManager->get('MagentoCustomerModelSession');
if($customerSession->isLoggedIn())
$welcomeMessage = $block->getWelcome();

else
$welcomeMessage = 'Hi Guest!';



sign-in option automatically remove for login customer.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 18 at 11:28

























answered Jul 18 at 4:47









Sweety MasmiyaSweety Masmiya

4672 silver badges12 bronze badges




4672 silver badges12 bronze badges












  • is this feasible while designing any other website using magento

    – Naiwrita09
    Jul 18 at 4:49











  • Can you please elaborate your question?

    – Sweety Masmiya
    Jul 18 at 4:51











  • Suppose I am designing a website using magento 2 then will this change in code work for the same task

    – Naiwrita09
    Jul 18 at 4:53











  • If you will create another website with Magento then also this code is usable for you.

    – Sweety Masmiya
    Jul 18 at 4:56











  • Ok thank you. and if I use the other theme and not luna?

    – Naiwrita09
    Jul 18 at 5:11

















  • is this feasible while designing any other website using magento

    – Naiwrita09
    Jul 18 at 4:49











  • Can you please elaborate your question?

    – Sweety Masmiya
    Jul 18 at 4:51











  • Suppose I am designing a website using magento 2 then will this change in code work for the same task

    – Naiwrita09
    Jul 18 at 4:53











  • If you will create another website with Magento then also this code is usable for you.

    – Sweety Masmiya
    Jul 18 at 4:56











  • Ok thank you. and if I use the other theme and not luna?

    – Naiwrita09
    Jul 18 at 5:11
















is this feasible while designing any other website using magento

– Naiwrita09
Jul 18 at 4:49





is this feasible while designing any other website using magento

– Naiwrita09
Jul 18 at 4:49













Can you please elaborate your question?

– Sweety Masmiya
Jul 18 at 4:51





Can you please elaborate your question?

– Sweety Masmiya
Jul 18 at 4:51













Suppose I am designing a website using magento 2 then will this change in code work for the same task

– Naiwrita09
Jul 18 at 4:53





Suppose I am designing a website using magento 2 then will this change in code work for the same task

– Naiwrita09
Jul 18 at 4:53













If you will create another website with Magento then also this code is usable for you.

– Sweety Masmiya
Jul 18 at 4:56





If you will create another website with Magento then also this code is usable for you.

– Sweety Masmiya
Jul 18 at 4:56













Ok thank you. and if I use the other theme and not luna?

– Naiwrita09
Jul 18 at 5:11





Ok thank you. and if I use the other theme and not luna?

– Naiwrita09
Jul 18 at 5:11

















draft saved

draft discarded
















































Thanks for contributing an answer to Magento Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282453%2fhow-to-customise-header-for-guest-and-logged-in-user-in-magento2-programmaticall%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form