[wp-trac] [WordPress Trac] #60922: get_custom_logo returns an empty link when no logo image is set

WordPress Trac noreply at wordpress.org
Fri Apr 5 11:22:27 UTC 2024


#60922: get_custom_logo returns an empty link when no logo image is set
--------------------------+------------------------------
 Reporter:  afercia       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Themes        |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:  accessibility
--------------------------+------------------------------

Old description:

> When a custom logo image is not set, `get_custom_logo()` returns an empty
> link regardless.
>
> Empty links are far from ideal for SEO and accessibility and should be
> avoided.
>
> Example of the returned HTML:
>
> {{{
> <a href="http://localhost:8889/" class="custom-logo-link" rel="home"></a>
> }}}
>

> With the Site Logo block of the editor, the HTML would be:
>

> {{{
> <div class="wp-block-site-logo">
>     <a href="http://localhost:8889/" class="custom-logo-link"
> rel="home"></a>
> </div>
> }}}
>
> where the link markup comes from `get_custom_logo()`
>
> To reproduce:
> - Use Twenty Twent-Four as active theme.
> - Go to the site editor, edit the Blog Home template.
> - Select the Site Logo block. Add it if necessary.
> - Do not set a logo image, leave the block empty and save.
> - Go to the front end.
> - Inspect the source and observe the site logo link is an empty link.

New description:

 When a custom logo image is not set, `get_custom_logo()` returns an empty
 link regardless.

 Empty links are far from ideal for SEO and accessibility and should be
 avoided.

 Example of the returned HTML:

 {{{
 <a href="http://localhost:8889/" class="custom-logo-link" rel="home"></a>
 }}}


 With the Site Logo block of the editor, the HTML would be:


 {{{
 <div class="wp-block-site-logo">
     <a href="http://localhost:8889/" class="custom-logo-link"
 rel="home"></a>
 </div>
 }}}

 where the link markup comes from `get_custom_logo()`

 To reproduce:
 - Use Twenty Twent-Four as active theme.
 - Go to the site editor, edit the Blog Home template.
 - Select the Site Logo block. Add it if necessary.
 - Set a logo image and save.
 - Go to the Media Library and delete the image you set as site logo.
 - Go to the front end.
 - Inspect the source and observe the site logo link is an empty link.

--

Comment (by afercia):

 After some debugging, turns out the root problem is that
 `get_custom_logo()` first retrives the logo ID by retrieving
 `get_theme_mod( 'custom_logo' )`. That option is set when setting a site
 logo but it's noc cleared when the image is deleted from the Media Library
 (or deleted from the file system).

 `get_custom_logo()` does check if the`$custom_logo_id` exists but that
 comes from the `site_logo` option in the `wp_options` table. That value
 still exists even when the referenced image is deleted from the Media
 Library.

 `get_custom_logo()` does _not_ check whether the image actually exists.
 When the image is deleted from the Media Library,
 [https://github.com/WordPress/wordpress-
 develop/blob/ea7888f114a9fe3c318716684d21703fe146ecbd/src/wp-includes
 /general-template.php#L1098 wp_get_attachment_image] returns an empty
 string and there's no check for that, the markup is rendered regardless
 and prints an empty string.

 Looks like this function ''assumes'' the image does exist when the
 custom_logo/site_logo option is set, which isn't true.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60922#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list