Stop Request for Logo Image When Hidden

|

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:,';
	}
}

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.