Get the logo information dynamically and use it in further operations like comparing, validating logo details, designing purpose, etc. using the below solution:
Thank you for subscribing.
Something went wrong.
You can get all block functions by printing like below in your .phtml file
A logo is the visual representation of your brand or store. It can communicate a message about who you are, what you do, and what your values are!
Method to Get Logo URL, Alt Text, Logo Height and Width in Magento 2
Never miss Magento tips, tricks, tutorials, and news.
class LogoDetail extends MagentoFrameworkViewElementTemplate
public function __construct(
array $data = 
$this->logo = $logo;
public function getLogoWidth()
return $this->logo->getLogoWidth(); // To get Logo image width
public function getLogoHeight()
return $this->logo->getLogoHeight(); // To get Logo image height
public function getLogoSrc()
return $this->logo->getLogoSrc(); // To get Url of Logo image
public function getLogoAlt()
return $this->_logo->getLogoAlt(); // To get Url of Logo image alternet text
When we upload or change a logo in our store, it sets logo-related information like logo size, logo URL, alt text and saved in various file formats such as PNG, GIF, JPG, or JPEG.
echo $block->getLogoWidth();//Print logo Width
echo $block->getLogoHeight();//Print logo Height
echo $block->getLogoSrc();//Print logo path
echo $block->getLogoAlt();//Print logo alt text
After installing Magento 2, one of the essential things you need to do is change the logo on the website.
I would be happy to help.
In that scenario, we have to dynamically get logo URL, alt text, logo height and width in Magento 2 to compare the updated logo with the existing one and validate logo information.
That’s easy, right?
Use the below code in your block file.
Get Weekly Updates
If you have any doubts regarding this post, just mention them in the Comments section below.
While designing our Magento 2 store, we often need a perfect-sized logo that matches the size of our web page. For instance, the size of a logo must enlarge when our site transforms to the larger screen and reduce when the store opens on the mobile screen.
Feel free to share the solution with Magento Community via social media.