Magento 2 : Adding logo in a custom extension
-
24-01-2021 - |
Question
I'm creating an extension where I should be able to call the logo which has been uploaded to Magento to show up in the home page.
So I upload the logo to:
Content -> Design -> Configuration -> Edit (Global) -> Header -> Logo Image
I have been investigating how Magento calls the logo:
vendor/magento/module-theme/Block/Html/Header/Logo.php
What would I need to add to my custom module in order to get this logo and show it. Thank you.
Solution
You need to inject \Magento\Theme\Block\Html\Header\Logo
class in your block/controller and call getLogoSrc()
method on its object to get the logo url and getLogoAlt()
to get alt text.
Once you have it you can show it image tag in a phtml.
You can see a relevant tutorial here - https://www.mageplaza.com/how-get-logo-url-alt-text-logo-size-magento-2.html