Custom Image Header API

Recently we added some API to WordPress 2.1 to make adding custom image headers to themes much easier. We use this API for the themes on wordpress.com. The API is pretty simple. First, define some defaults:

define('HEADER_TEXTCOLOR', '009193');

define('HEADER_IMAGE', '%s/images/spring_flavour/header_bg.jpg'); // %s is theme dir uri

define('HEADER_IMAGE_WIDTH', 690);

define('HEADER_IMAGE_HEIGHT', 115);

Next you need to define a couple of functions. One styles the blog header and the other styles the admin header. See the functions header_style() and admin_header_style() defined in this sample theme functions.php.

Those functions can now be registered as callbacks with the add_custom_image_header() function.

add_custom_image_header('header_style', 'admin_header_style');

add_custom_image_header() does the work of creating a “Custom Image Header” page in the “Presentation” menu. The “Custom Image Header” page handles allowing users to change the header text color and upload and crop new header images.

Custom Image Header

Define a few constants and a couple of functions and your theme can easily add custom image header support. Here are some more sample functions.php files from various themes that use the custom image header API.

24 thoughts on “Custom Image Header API

  1. That’s very cool. I asked Andy about this so that I could use it with Regulus but never got a response so I ended up going with my own version (which isn’t as good). I am working on a new theme and will be sure to use this in it.

    I just need WP 2.1 to be released now 🙂

  2. it’s worth mentioning that for theme authors, all this stuff needs to be wrapped in if (function_exists(''))

    and.. i don’t know what function to check for.

  3. I’ve successfully added these calls to the fall-season-10 theme. I’m having another problem, though. Uploads are not working.

    I’m using the nightly 2-12 build on RedHat ES. When I try to upload the custom header file, I get the following error:

    Unable to create directory /var/www/vhosts/test.com/httpdocs/wp-content/blogs.dir/1/files/. Is its parent directory writable by the server?

    I’ve searched the forums and tried:
    1. permission settings
    2. chowning to apache
    3. Checking safe mode (it’s off)
    4. tried itdamagers htaccess settings

    All of these suggestions have failed.

    Any other suggestions?

  4. Hello,

    doest this API work with WordPress MU. And does it allow a storage in the blogs.dir directory ?

Leave a Reply to Holistic Networking - Lorelle’s WordPress 2.1 TeasersCancel reply