Site logo

[Resolved] How to add height and width attributes to bottom element header

Home Forums Support [Resolved] How to add height and width attributes to bottom element header

Home Forums Support How to add height and width attributes to bottom element header

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1715882
    metcomllc@aol.com

    How do I add height and width attributes to bottom element header https://www.tryhypnosisnow.com

    #1715895
    Leo
    Staff
    Customer Support

    Hi there,

    Not sure if I fully understand.

    Can you explain a bit more?

    Thanks!

    #1715906
    metcomllc@aol.com

    The image which is bottom header element needs to have height and width attributes for Core Vitals

    #1716113
    Elvin
    Staff
    Customer Support

    Hi there,

    I’ve checked your site’s performance report and I think you’re pertaining to the logo image you’ve placed as “header image”.

    You can use the code snippet here to address the flag for desktop:
    https://docs.generatepress.com/article/generate_logo_output/#setting-a-width-and-height

    Change width="999" height="999" value from 999 to your preference.

    And you can use this one for mobile header:
    https://docs.generatepress.com/article/generate_mobile_header_logo_output/#setting-a-width-and-height

    Same idea for the mobile snippet. 🙂

    #1716456
    metcomllc@aol.com
    #1716494
    metcomllc@aol.com

    The image attributes do not show for Core Vitals after adding this

    add_filter( 'generate_logo_output','tu_logo_atts', 10, 2 ); 
    function tu_logo_atts( $output, $logo ) {
    	printf(
    		'<div class="site-logo">
    			<a href="%1$s" title="%2$s" rel="home">
    				<img width="1024" height="174" class="header-image" src="%3$s" alt="%2$s" title="%2$s" />
    			</a>
    		</div>',
    		esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
    		esc_url( apply_filters( 'generate_logo', $logo ) )
    	);
    }
    #1716510
    metcomllc@aol.com

    I wasn’t sure what size to make the image so I used the size listed in the media library. Is that right?

    The image attributes do not show for Core Vitals after adding this

    add_filter( 'generate_logo_output','tu_logo_atts', 10, 2 ); 
    function tu_logo_atts( $output, $logo ) {
    	printf(
    		'<div class="site-logo">
    			<a href="%1$s" title="%2$s" rel="home">
    				<img width="1024" height="174" class="header-image" src="%3$s" alt="%2$s" title="%2$s" />
    			</a>
    		</div>',
    		esc_url( apply_filters( 'generate_logo_href' , home_url( '/' ) ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
    		esc_url( apply_filters( 'generate_logo', $logo ) )
    	);
    }

    but I have been using this code snippet for a link on my desktop header

    add_filter( 'generate_logo_output', 'tu_logo_target', 10, 3 );
    function tu_logo_target( $output, $logo_url, $html_attr ) {
    	printf(
    		'<div class="site-logo">
    			<a href="%1$s" title="hypnosis nyc hypnotherapy New York City" rel="home" rel="noopener" alt="Hypnotherapy NYC Hypnosis Center #1 Doctor Referred Hypnotist">
    				<img %3$s />
    			</a>
    		</div>',
    		esc_url( apply_filters( 'generate_logo_href' , "tel:1-877-800-6443" ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
    		$html_attr
    	);
    }
    #1716895
    Leo
    Staff
    Customer Support

    Try this:

    add_filter( 'generate_logo_output', 'tu_logo_target', 10, 3 );
    function tu_logo_target( $output, $logo_url, $html_attr ) {
    	printf(
    		'<div class="site-logo">
    			<a href="%1$s" title="hypnosis nyc hypnotherapy New York City" rel="home" rel="noopener" alt="Hypnotherapy NYC Hypnosis Center #1 Doctor Referred Hypnotist">
    				<img width="1024" height="174" %3$s />
    			</a>
    		</div>',
    		esc_url( apply_filters( 'generate_logo_href' , "tel:1-877-800-6443" ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
    		$html_attr
    	);
    }
    #1716950
    metcomllc@aol.com

    Thank you.

    How do I determine and add height and width attributes to my mobile header:

    This is a snippet I use

    add_filter( 'generate_mobile_header_logo_output','tu_mobile_logo_atts' );
    function tu_mobile_logo_atts( $output ) {
    	printf( 
    		'<div class="site-logo mobile-header-logo">
    			<a href="%1$s" title="%2$s" rel="home" alt="Hypnotherapy NYC Hypnosis Center #1 Doctor Referred Hypnotist Click to Call">
    				<img class="header-image" src="%3$s" alt="%2$s" title="hypnosis nyc hypnotherapy New York City" />
    			</a>
    		</div>',
    		esc_url( apply_filters( 'generate_logo_href' , "tel:1-877-800-6443" ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) ),
    		esc_url( apply_filters( 'generate_mobile_header_logo', "https://www.tryhypnosisnow.com/wp-content/uploads/2020/04/hypnosis-nyc-hypnotherapy-New-York-City.jpg" ) ),
    		esc_attr( apply_filters( 'generate_logo_title', get_bloginfo( 'name', 'display' ) ) )
    	);
    }

    This is added CSS

    #mobile-header img { width: 100%; height: auto; }
    h1.entry-title {
    display: none;
    }
    @media (max-width: 768px) {
        .page-hero {
            background-image: url(https://www.tryhypnosisnow.com/wp-content/uploads/2020/04/Hypnosis-NYC-for-quit-smoking-weight-loss-anxiety-phobias-confidence.jpeg);
        }
    }
    @media (min-width: 769px) {
        .main-navigation li.search-item {
            display: none !important;
        }
    }
    #mobile-header .inside-navigation {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
    }
    .main-navigation .mobile-bar-items {
        order: 4;
    }
    input.ticket-selector-submit-btn {
    background-color: #001de0!important; color: #fffff;
    }
    #1718124
    Leo
    Staff
    Customer Support

    The mobile header logo already has a width and height added:
    https://www.screencast.com/t/s7arbc8Jj

    #1735632
    metcomllc@aol.com

    Thank you for your help.

    #1735822
    Leo
    Staff
    Customer Support

    No problem 🙂

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.