WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 8 weeks ago

#36640 new enhancement

Customize: get_custom_logo should allow the image tag to be filtered independently

Reported by: achbed Owned by:
Milestone: 5.4 Priority: normal
Severity: normal Version: 4.5
Component: Customize Keywords: has-patch dev-feedback
Focuses: Cc:
PR Number:

Description

To allow for further customization of the image tag used in the custom logo, I propose adding a get_custom_logo_img filter to get_custom_logo. This will allow for cleaner modification of the a tag content.

This would be useful in optionally adding accessibility on the image and other content within the home link.

Attachments (3)

custom-logo-img_filter.patch (1.0 KB) - added by achbed 4 years ago.
custom-logo-imgattr_filter.patch (1.1 KB) - added by achbed 4 years ago.
Alternate: Filter for the attributes only instead of the entire img tag
36640.diff (936 bytes) - added by dlh 2 months ago.

Download all attachments as: .zip

Change History (10)

#1 @westonruter
4 years ago

  • Keywords has-patch added
  • Version changed from trunk to 4.5

Giving more control over the generation of the img markup makes sense, but we'd want to make sure that custom-logo-link class is always includes as otherwise the selective refresh selector will fail to match. Well, I suppose we could still allow it to be changed, but the plugin that filters get_custom_logo_img should also make sure it updates $wp_customize->selective_refresh->get_partial( 'custom_logo' )->selector as required. This should be noted in the filter description.

#2 @achbed
4 years ago

I supposed for accessibility and theming purposes, we could simply allow filtering the image tag attributes. We can then enforce the custom-logo-link class after the filter returns.

@achbed
4 years ago

Alternate: Filter for the attributes only instead of the entire img tag

@dlh
2 months ago

#3 @dlh
2 months ago

  • Milestone set to 5.4

[45028] removed itemprop from the default custom logo attributes. The get_custom_logo and wp_get_attachment_image_attributes filters were suggested as options for restoring itemprop, and while those certainly work, the filter suggested here would arguably make the process a little less cumbersome.

36640.diff refreshes the previous patch with a couple changes:

  • Rename the filter to get_custom_logo_image_attributes for consistency with wp_get_attachment_image_attributes.
  • Move the attachment ID to the second filter parameter under the assumption that it'll be more common to need that ID than the current blog ID.

As highlighted in comment:2, the custom-logo-link class should still be unaffected by the filter.

I'll check in with #core-themes for other opinions, and maybe there can be a yea or nay on this enhancement during the 5.4 cycle.

This ticket was mentioned in Slack in #core-themes by dlh. View the logs.


2 months ago

#5 @dlh
2 months ago

  • Keywords dev-feedback added

#6 @joyously
8 weeks ago

The description says

This will allow for cleaner modification of the a tag content.
...other content within the home link

So why is the filter on the image attributes?

#7 @dlh
8 weeks ago

Filtering the image attributes was suggested by the reporter in comment:2 as a simpler approach to apply the modifications they were looking for.

The title, description, and comment:1 also referenced the image tag specifically, so I took it to be the focus of the request, but perhaps that was mistaken.

For the itemprop example, at least, being able to modify the attributes array seems to me like it would be simpler than modifying the HTML content within the <a>.

Note: See TracTickets for help on using tickets.