Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Set explicit width and height

  • PageSpeed Insights tells me I need to set explicit width and height on mobile nav logo. How do I do that?
    Screenshot 2023-06-02 at 5.32.45 PM.png

  • Hi there,

    the SVG you’re using has no width or height attributes in its markup.
    Ideally you would want to save an SVG that has those attributes.

    Otherwise you can use the PHP Snippet provided here to add them in the theme:

    https://docs.generatepress.com/article/generate_mobile_header_logo_output/#setting-a-width-and-height

    Note the line:

    <img src="%3$s" width="999" height="999" alt="%4$s" />

    You need to set the width and height you require for your image.

  • Thank you, David.

  • You’re welcome

  • Hi David,

    Just wanted to follow up on this. In addition to setting the height and width of the logo, would I also need to add the URL “%3$s” to the image and the alt text “%4$s”?

    Secondly, the code you provided is just for SVG logos, right? So, if I have other svg images that aren’t logos can I use this code snippet? In my case, there are 2 other svg images that need to have height and width set. I’m not too concerned with it at this point, I just want to know for my own knowledge.

  • Hi Maria,

    would I also need to add the URL “%3$s” to the image and the alt text “%4$s”?

    No, you don’t need to, as these info are there by default.

    Secondly, the code you provided is just for SVG logos, right?

    Usually, image logos have the width and height attribute by default, they don’t require this snippet.

    So, if I have other svg images that aren’t logos can I use this code snippet?

    No, the snippet is only for logo.

    In my case, there are 2 other svg images that need to have height and width set.

    Do the 2 other SVG images get the flag? Let me know!

  • Hi Ying,

    Yes, I get the error on both the logo and image. Here’s the screenshot: https://www.screencast.com/t/JENyvbVEW4wY

  • Can you share the link to your site where I can see both images?

    Let me know 🙂

  • Hum…I tried uploading your SVG to my site, and the SVG image does have width and height attributes.

    How did you upload the SVG?

    I also wonder if the cache plugin is doing something to it, can you disable the cache plugin first, then install the Safe SVG plugin and then upload the image again?

    Let me know 🙂

  • I’m not going to worry about it. Thanks for looking into it.

  • No problem 🙂

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