Custom Image Header API

January 7, 2007
by Ryan

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 Responses
  1. January 8, 2007

    Thanks for the tutorial. It seems to be easy to setup. One question though: does this work in WordPressMU too?

  2. January 8, 2007

    That’s pretty sweet! More ease with customizations. Awesome. I am sure many people will be glad about this.

  3. January 8, 2007

    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 :)

  4. January 8, 2007

    WOW! Just what I need … if only I could figure out the techie bits on how to get this working on my blog :(

  5. January 8, 2007

    Nice one! Should be very handy… I think I’m going to have to get hold of the 2.1 beta and have a play!

  6. January 28, 2007

    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.

  7. February 12, 2007
    adaptiman permalink

    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?

  8. May 11, 2007
    JCLT permalink

    Hello,

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

Trackbacks & Pingbacks

  1. » Temi con immagini di testata personalizzabili » WordPress Italy
  2. Vorschau auf Wordpress 2.1 » Bloganbieter.de
  3. WordPress Francophone » Quelques détails sur WordPress 2.1
  4. Wordpress 2.1 Preview - Telagon Sichelputzer
  5. Holistic Networking - Lorelle’s WordPress 2.1 Teasers
  6. WordPress Themes by Sadish » What is brewing in our cafe !?
  7. Unnamed 1.1 For WordPress 2.1 at iqwolf
  8. Custom Image Header API · Braille WordPress Theme
  9. ..::| archGFX | Disconnected 1.2 |::..
  10. Jason » Blog Archive » Wordpress.com Theme Repository
  11. Diario a Borbo · [Theme] Tarski 1.4
  12. 狗爺語錄 » Very angry — WordPress is crippleware!
  13. Custom Image Header API « Linklove
  14. Wordpress 主题汉化 Unnamed 1.1 | lidecheng's weblog
  15. Thad Allender | Visualization Wordpress Magazine Theme
  16. The WhimWham » Blog Archive » Customising ChaoticSoul

Comments are closed for this entry.