Question

I have successfully created a custom theme as a child of Luma theme in my Magento CE 2.0.12 installation.

But if I add below code in my layout/theme.xml file, I am not able to add a title attribute to img tag of Logo:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="logo">
           <arguments>
              <argument name="logo_file" xsi:type="string">images/mytheme_logo.svg</argument>
              <argument name="logo_alt" xsi:type="string">Custom Alt</argument>
              <argument name="logo_title" xsi:type="string">Custom's Logo</argument>
              <argument name="logo_img_width" xsi:type="number">200</argument>
              <argument name="logo_img_height" xsi:type="number">200</argument>
           </arguments>
        </referenceBlock>
    </body>
</page>

Please suggest how to add additional attribute to img tag of Logo.

Was it helpful?

Solution

You need to override template of logo.phtml into your custom theme.

Follow below steps :

  1. Assuming you have already created custom theme and its working fine and activated !! (Location is : app/design/frontend/VendorName/themename)
  2. Create one folder in the your custom theme directory name Magento_Theme
  3. Now create logo.phtml file in "Magento_theme/templates/html/header/logo.phtml" on this location.
  4. Copy your default logo.phtml file from theme and paste its content into your custom logo.phtml file. Add title attribute to that image tag.

logo.phtml code should be like below :

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

// @codingStandardsIgnoreFile

/**
 * @var \Magento\Theme\Block\Html\Header\Logo $block
 */
?>
<?php $storeName = $block->getThemeName() ? $block->getThemeName() : $block->getLogoAlt();?>
<span data-action="toggle-nav" class="action nav-toggle"><span><?php /* @escapeNotVerified */ echo __('Toggle Nav') ?></span></span>
<?php if ($block->isHomePage()):?>
    <strong class="logo">
<?php else: ?>
    <a class="logo" href="<?php echo $block->getUrl(''); ?>" title="<?php /* @escapeNotVerified */ echo $storeName ?>">
<?php endif ?>
        <img src="<?php /* @escapeNotVerified */ echo $block->getLogoSrc() ?>"
             alt="<?php /* @escapeNotVerified */ echo $block->getLogoAlt() ?>"
             <?php echo $block->getLogoWidth() ? 'width="' . $block->getLogoWidth() . '"' : '' ?>
             <?php echo $block->getLogoHeight() ? 'height="' . $block->getLogoHeight() . '"' : '' ?>
       title="TESTESTESTEST" />
<?php if ($block->isHomePage()):?>
    </strong>
<?php else:?>
    </a>
<?php endif?>

Here i have added title="TESTESTESTEST" it shows on the logo image. Clear the cache and check

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top