1 | | When uploading a custom header image allow users to specify the desired height of the image. |
| 1 | If a theme allows flexible header images the custom header feature should adjust the crop settings on upload to let the image through. |
| 2 | |
| 3 | '''Theme Support''' |
| 4 | |
| 5 | {{{add_theme_support( 'allow_flexible_header_height', 200 );}}} [[BR]] Where 200 is the maximum height allowed. |
| 6 | |
| 7 | {{{add_theme_support( 'allow_flexible_header_width', 1000 );}}} [[BR]] Where 1000 is the maximum width allowed. |
| 8 | |
| 9 | '''Custom Header Code''' |
| 10 | |
| 11 | 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. |
| 12 | |
| 13 | If the option is on but dimension value is false or 0, let any size through (no crop at all). |
5 | | Appearance > Header could show the height as a text input field with the default height as the value. After you upload an image the cropper tool would use the value you entered for the height. |
6 | | |
7 | | The value would fall back to height value defined in {{{HEADER_IMAGE_HEIGHT}}} in the theme functions.php file if not changed by the user. See attached screenshot for example of the editable height. |
8 | | |
9 | | '''Theme Support''' |
10 | | |
11 | | To set a default value but allow overriding it from Appearance > Header use: |
12 | | {{{ |
13 | | define( 'HEADER_IMAGE_HEIGHT', '200' ); |
14 | | define( 'ALLOW_CUSTOM_HEADER_IMAGE_HEIGHT', true ); |
15 | | }}} |
16 | | Default value for {{{ALLOW_CUSTOM_HEADER_IMAGE_HEIGHT}}} is false. |
17 | | |
18 | | To use the header image in template files use {{{HEADER_IMAGE_HEIGHT}}} value in HTML attributes or use dynamic CSS to use the header image as a background image and set the height of its container to {{{HEADER_IMAGE_HEIGHT}}}. |
19 | | |
20 | | Note: If using this feature themes should avoid having a hard-coded height for the header image in the styles used for layout. |
21 | | |
22 | | '''Crop Without Height''' |
23 | | |
24 | | A tangential idea: Allow a header image to be uploaded constrained by width but not height in the crop tool. After upload use the image height as the custom height value for the theme. |
25 | | |
26 | | In this case, in functions.php theme authors could set the height definition to "custom" default value and when calling {{{HEADER_IMAGE_HEIGHT}}} in templates it'd return the height of the uploaded image. |
27 | | {{{ |
28 | | define( 'HEADER_IMAGE_HEIGHT', 'custom' ); |
29 | | define( 'ALLOW_CUSTOM_HEADER_IMAGE_HEIGHT', true ); |
30 | | }}} |
| 17 | If a theme supports this, list the maximum dimensions in Appearance > Header. If no maximums are defined, leave it blank. |