Stop Request for Logo Image When Hidden

Written by Dan Mossop

When you hide the logo in the Divi, you may notice that a request for the logo image is still made by the page. This is because the logo image is hidden, but is still referenced by the HTML source of the page. So the browser loads the image in anticipation of the logo being displayed (which it actually won't). Here's how to address that.

Change the logo element's src using PHP

While it's possible to fully remove the logo image tag from the page, this may affect code which expects it to be there. One way to avoid this is to change just the URL of the logo, to something that doesn't trigger a request by the browser. (Note that it's invalid HTML to have no src attribute on an image tag, so we need to supply something valid for the src, but that doesn't trigger a request).

You can use the following PHP code to do so:

add_filter('et_get_option_et_divi_divi_logo', 'db_empty_logo_src');

if (!function_exists('db_empty_logo_src')) {
	function db_empty_logo_src($url) {
		if (is_admin()) return $url;
		return 'data:,';
	}
}

Effortlessly Manage Code with Divi PHP Code Module

Run PHP Code Directly in your Divi Layouts. Achieve endless customization without altering core Divi functionalities. The Divi PHP Code Module allows seamless PHP integration, ensuring your site remains functional and dynamic.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

2 Comments

  1. Thanks. My issue was certain browsers were showing a placeholder and text where the image would be if it were not set to hidden. I didn't want to mess with the PHP code as you suggest so I found at Bing AI the following line of code to add to the DIVI>Theme Options>General>Custom CSS:

    #logo { display: none; }

    It worked. No more placeholder

    Reply
    • Hey Scaramouche, thanks for sharing! Your workaround of using CSS to hide the logo is a straightforward and clean solution. It is worth pointing out that with the CSS-only solution the browser will likely still fetch the logo from the server. The logo won't show, but there may be a (slight) performance impact, and it is this that the PHP code aims to address. Thanks again!

      Reply

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

Your email address will not be published. Required fields are marked *.

We may earn a commission when you visit links on our website.