Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1238416
    tunedotcom
    Participant

    I need to add a specific data attribute to the site’s logo image in the nav for google tag manager purposes. I was able to use nav_menu_link_attributes to manipulate the nav but can’t find a solution for the logo. Any help is appreciated, thanks.

    #1238666
    Prasant Rai
    Moderator

    Hello There,

    Thanks for writing in!

    Can you please provide the URL of your website so we can see your current setup and suggest you a solution accordingly?

    Thanks.

    #1238736
    tunedotcom
    Participant

    Yes, it’s tune.com. Thanks.

    #1238861
    Paul R
    Moderator

    Hi,

    You can create the file _brand.php in wp-content/themes/x-child/framework/views/global then copy the code below into that file

    
    <?php
    
    // =============================================================================
    // VIEWS/GLOBAL/_BRAND.PHP
    // -----------------------------------------------------------------------------
    // Outputs the brand.
    // =============================================================================
    
    $site_name        = get_bloginfo( 'name' );
    $site_description = get_bloginfo( 'description' );
    $logo             = x_make_protocol_relative( x_get_option( 'x_logo' ) );
    $site_logo        = '<img src="' . $logo . '" alt="' . $site_description . '">';
    
    ?>
    
    <?php echo '<h1 class="visually-hidden">' . $site_name . '</h1>'; ?>
    
    <a href="<?php echo home_url( '/' ); ?>" class="<?php x_brand_class(); ?>" title="<?php echo $site_description; ?>">
      <?php echo ( $logo == '' ) ? $site_name : $site_logo; ?>
    </a>
    

    You can add your data attribut on this line of code.

    $site_logo        = '<img src="' . $logo . '" alt="' . $site_description . '">';
    

    eg.

    
    $site_logo        = '<img data="YOUR DATA HERE" src="' . $logo . '" alt="' . $site_description . '">';
    

    Hope that helps.

    #1239797
    tunedotcom
    Participant

    Thank you. That worked out well 🙂

    #1240087
    Nico
    Moderator

    Happy to hear that.

    Feel free to ask us again.

    Thanks.

  • <script> jQuery(function($){ $("#no-reply-1238416 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>