WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 years ago

#17242 closed task (blessed)

Themes: Allow flexible sizes for custom header uploads — at Version 13

Reported by: lancewillett Owned by:
Milestone: 3.4 Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch commit
Focuses: Cc:

Description (last modified by lancewillett)

If a theme allows flexible header images the custom header feature should adjust the crop settings on upload to let the image through.

Theme Support

add_theme_support( 'allow_flexible_header_height', 200 );
Where 200 is the maximum height allowed.

add_theme_support( 'allow_flexible_header_width', 1000 );
Where 1000 is the maximum width allowed.

Custom Header Code

If the theme_support option exists and passes second argument (dimension as an integer), and the uploaded image dimension is higher, crop to size. If the uploaded image dimension is lower, save it with no crop.

If the option is on but dimension value is false or 0, let any size through (no crop at all).

Admin UI

If a theme supports this, list the maximum dimensions in Appearance > Header. If no maximums are defined, leave it blank.

Change History (15)

comment:1 follow-up: ocean903 years ago

Why we should do this only for the height?

comment:2 nacin3 years ago

One thing to note, the constants are largely left over from when we had header images in Kubrick. They're ugly and inflexible. It would be great to move away from them everywhere possible, and go in the direction of add_theme_support() with an array of extra arguments being passed to it.

comment:3 follow-up: nacin3 years ago

Directly referring to this ticket, I don't understand why there needs to be a UI for this. If the theme allows flexible height images, then they can adjust the crop upon upload, assuming the image is not exactly the default dimensions. Simple enough.

comment:4 iandstewart3 years ago

  • Cc ian@… added

comment:5 follow-up: aaroncampbell3 years ago

Things I've struggled with relating to this ticket:

  • It's really annoying that you can only use one header image and one background image. This is only tangentially related to this ticket, but it would be nice to allow a theme to use multiple "header images" (obviously allowing them to name them differently) each with their own sub page area to manage them from. Consider the simple case of a theme that allows a background image, a header image, and a logo.
  • Since I see people trying to use this for logos pretty often (even tried it myself before I gave up on it) it would be nice to be able to set a maximum width or maximum height (and I mean 'or', setting a max width and no max height would be ideal in most cases). Basically allowing someone to say "as long as it fits here it's fine".
Last edited 2 years ago by aaroncampbell (previous) (diff)

comment:6 in reply to: ↑ 1 lancewillett3 years ago

Replying to ocean90:

Why we should do this only for the height?

Because theme width isn't flexible generally, but height of the header is.

Replying to nacin:

It would be great to move away from them everywhere possible, and go in the direction of

add_theme_support() with an array of extra arguments being passed to it.

Totally agree.

comment:7 in reply to: ↑ 5 lancewillett3 years ago

Replying to aaroncampbell:

It's really annoying that you can only use one header image and one background image. This is only tangentially related to this ticket

I agree. See #15100 (reusing header images) and #17241 (see note about reusing background images).

it would be nice to be able to set a maximum width or maximum height (and I mean 'or', setting a max width and no max height would be ideal in most cases). Basically allowing someone to so "as long as it fits here it's fine.

Good idea. That way it's flexible up to the constraints of the theme layout. I think that would work for logos, but for full-width header images it might lead to some ugly-ish layouts if the header image doesn't fill the width allotted.

comment:8 in reply to: ↑ 3 lancewillett3 years ago

Replying to nacin:

If the theme allows flexible height images, then they can adjust the crop upon upload, assuming the image is not exactly the default dimensions. Simple enough.

Let's do that. :)

That approach is what I have in the ticket under "Crop Without Height" but maybe implemented with add_theme_support and not the ugly definitions.

comment:9 follow-up: aaroncampbell3 years ago

Replying to lancewillett:

Replying to ocean90:

Why we should do this only for the height?

Because theme width isn't flexible generally, but height of the header is.

I'm not sure what percentage of themes allow it, but even on fixed width themes is not that uncommon to allow the header image to continue out past the fixed width. I'll upload a screenshot of a theme where we could use a flexible width as well (in this example there's no background image, but you CAN have a background image in addition to the header in this theme).

comment:10 matveb3 years ago

  • Cc mv@… added

comment:11 in reply to: ↑ 9 lancewillett3 years ago

  • Cc lance@… added
  • Keywords 2nd-opinion added
  • Summary changed from Themes: Allow users to set the height for custom header image to Themes: Allow any size custom header image

Replying to aaroncampbell:

I'm not sure what percentage of themes allow it, but even on fixed width themes is not that uncommon to allow the header image to continue out past the fixed width.

I'm seeing now that this could really be for both width and height, as ocean90 pointed out initially.

I think we should go with Nacin's idea that if a theme allows flexible header images the custom header code can adjust the crop settings on upload to let an image through.

Idea for the theme notation:

  • add_theme_support( 'allow_flexible_header_height', 200 );
    Where 200 is the maximum height allowed.
  • add_theme_support( 'allow_flexible_header_width', 1000 );
    Where 1000 is the maximum width allowed.

If the option is on and a second dimension argument is passed (integer), and the uploaded image dimension is higher, crop to size. If the uploaded image dimension is lower, save it with no crop.

If the option is on but dimension value is false or 0, let any size through (no crop at all).

The max dimension cropping is "nice-to-have" for this feature — but it would make this a great compromise between allowing flexibility while allowing theme authors to control the look of their themes to some extent.

It might also help with the case where a user uploads an original (potentially huge) image from their camera and want to use it as a header. :)

comment:12 ryan3 years ago

  • Milestone changed from Awaiting Review to 3.2

comment:13 lancewillett3 years ago

  • Description modified (diff)
  • Summary changed from Themes: Allow any size custom header image to Themes: Allow flexible sizes for custom header uploads
Note: See TracTickets for help on using tickets.