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;
I 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
add a comment |
I 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
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
add a comment |
I 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
I 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
luma-theme magento2.3.2
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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!');
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
add a comment |
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.
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
|
show 11 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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!');
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
add a comment |
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!');
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
add a comment |
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!');
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!');
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
add a comment |
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
add a comment |
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.
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
|
show 11 more comments
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.
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
|
show 11 more comments
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.
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.
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
|
show 11 more comments
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
|
show 11 more comments
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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