Blackbams Blog
development – digital arts – internet
Knowledge is free. No one may take possession of it.
Why does WordPress need another Header Images Plugin? Really, there are a lot of Plugins for this purpose so why did I have to write another one?
The answer is: All these plugins have a lot of code, it is hard to extend these by oneself and unfortunatly none if these is really simple to maintain, extend and to understand. I was searching for hours for the right header image Plugin which provides the functionality that i needed in a simple clean and easy way, without custom tables and buggy built-in uploads, wihout required theme support and so on. So here is my answer: A quick and easy WordPress Plugin to do this job.
Features
- Simple and easy management of header images
- Each possible state is covered, by using the WordPress template hierarchyfor diffentiation
- The Media Library is used for image management, images are saved by URL copy/paste (so external images can be used, too)
- Requires no extra tables
- NEW: Support for Custom Post Types (Single Custom Post Images) and Custom Taxonomies (Taxonomy Page Images)
- Clean install/uninstall
Installation
>> Download this Plugin <<
- Upload the Plugin to your wp-content/plugins/ folder
- Activate the Plugin
- Go to Settings -> Header Images and insert the image URLs (get the URLs from the media library)
- Paste one of the following codes into your theme:
NOTE:This code must be put into PHP brackets!
if(function_exists('chi_display_header')) { chi_display_header(); }
or this code, use concrete numbers for width and height in pixels:
if(function_exists('chi_display_header')) { chi_display_header($width,$height); }
Warning: You can only use conditional query tags after the posts_selection action hook in WordPress (the wp action hook is the first one through which you can use these conditionals). For themes, this means the conditional tag will never work properly if you are using it in the body of functions.php, i.e. outside of a function (http://codex.wordpress.org/Conditional_Tags).
How to change header images…
- Go to Settings ->Header images (general images)
- Meta Boxes at the bottom of post / page edit screen
- Category add/edit screen
FAQ
Q: The Plugin is not displaying the header images correctly. What is wrong?
- The function code must be pasted into one of your template files, the best place in most cases of use is the bottom of header.php
- This Plugin uses conditional tags. Please make sure that your wp_query object has been loaded correctly, before the code is executed.
Dieser Eintrag wurde am 25. June 2012 um 1:01 in der Kategorie Plugins, WordPress veröffentlicht. You can book the comments for this article RSS 2.0. Feedback, discussion, commendation and critics are welcome: Write a comment or trackback.
Tags: Header Images

Already 53 comments belonging to "Custom Header Images Plugin for WordPress":
Kommentare abonnieren (RSS) or URL Trackback
Heidi Reyes
says:
on 28. June 2012 at 07:48 on clock
Hello! I've installed this plugin and activated it. However, I don't know where to put the lines of code in my theme. Where do I put these lines of code?
if(function_exists('chi_display_header')) { chi_display_header(); }
if(function_exists('chi_display_header')) { chi_display_header($width,$height); }
Thank you for your time!
Blackbam
says:
on 04. July 2012 at 01:21 on clock
Hi there, first of all:
You only have to put ONE of these lines into the code for your Theme. When choosing the second line, you have to replace $width and $height with a concret number for the width and height of the header image in pixels, so for the basic functionality you need only the first of these lines of code.
You put these lines of could to the place where you want the header images to be shown - this could be:
header.php
index.php
or similar files.
Just put it to a place there you think the header images should appear, and possibly update your style.css for adequate styling, if required.
Maybe in some future versions I will include a Widget / Shortcode, but I think for most purposes it is best to put this function in your themes by hand.
David S
says:
on 09. July 2012 at 08:21 on clock
This is a great idea, and exaclty what I was looking for - however:
I have followed the instructions provided here and in readme.txt carefully, the plug-in is activated, I am able to provide the url for images in posts and pages. The code you provided is in the header.php, however no image shows in the page when published. When I look at the source code of page DOM all I see is , so nothing renders. Can't figure it out at all. Any help, please?
Thank you!
Blackbam
says:
on 09. July 2012 at 23:47 on clock
Hey David,
there can be various reasons for this unexpected behavior, so you can try the following things:
1. Go to Plugins -> Header Images and set a "Global Image Default URL", and make sure you do NOT have selected "Display nothing by default?". No check if the default image is displayed on each page.
1.1 The default image is displayed now
If the image is displayed now, then the problem is that the post data in your header.php file is not provided correctly by your theme. Please check if the global variables $post and $wp_query contain the correct data and are not empty or in a wrong state.
1.2 There is still no image to see
- Make sure that you embeded this function inside a part of you header which is called everytime, so do not write it into a construct which is called conditionally
- Make sure that you are using the absolute image URL using the full path
- Check if the default width/ default height in the Plugins' options are not set to zero
- Check if a div with id "chi_display_header" is in your HTML-Output - if not, the URL-data is empty and there must be a problem with your options table or $post
Please let me know if this helps.
kingfisher
says:
on 13. July 2012 at 16:32 on clock
i am such an amateur. my settings tab does not have a header tab, it is in the appearance tab. I am using the theme skylark. I would like to have the header image hold links to other pages in the site. Seems like your code should enable this but perhaps its only for self hosted sites?
Blackbam
says:
on 13. July 2012 at 19:49 on clock
Hey there,
currently the Plugin does not support built-in image links. I think the Plugin should work with wordpress.com blogs, but you have to modify the source of your theme, so you cannot update your themes without changing the code afterwards everytime. I will turn image linking into a feature request, which will be available with the next version of the Plugin.
Roger Pilon
says:
on 01. August 2012 at 16:31 on clock
I saw that you can use it also for Categories. It is said: Die URL zum Kategorie-Thumbnail - bitte den relativen Pfad benutzen i.d.R. /wp-content/..pfad_zum_bild/bild.jpg. I used Google Transaltion!! Can we only have thumnails or if I want bigger image, the plugin will grab it? In other words, can we use your plugin for categories? Like category " car" and you can have a header 600px / 250px for example displayed in the Cat page? Thanks
Blackbam
says:
on 26. August 2012 at 21:20 on clock
The Plugin is still under development, so in the next version there will be no more problems with internationalization.
It is said: "Please use relative path for category thumbnail."
Yes, you can use the Plugin for categories - exactly as you described it. Even custom taxonomies will be available in the next version.
If you experience any problems be free to post here for improvements of the Plugin.
Also sorry for the late reply, I was on holiday this month.
Fitguy1789
says:
on 05. September 2012 at 07:13 on clock
I recently Installed your plug-in and followed the instruction step by step however i am having trouble with my header image. the header image does not seem to change by page. Post image are working but i am having trouble changing the header image for every page..I always end up with the default image. The code always appears as text on my pages and it appears on every page. Posting images on post seems to be working just fine though...what am i doing wrong here?
Blackbam
says:
on 05. September 2012 at 12:54 on clock
Hey, sorry I should make this a little bit more clear for non-programmers. The code you have to paste into your site is PHP-code (server-side code).
So you have to paste
<?php if(function_exists('chi_display_header')) { chi_display_header(); } ?>
into your template.
As your template supports header images by default you should remove this function and replace it by the function of the Plugin. Choose a default image size of 1000 * 250. But be careful and make a backup first, so nothing can go wrong.
Fitguy1789
says:
on 05. September 2012 at 18:09 on clock
How exactly do i remove a function in my template? The Header image i want for my second page is showing on my second page now, but the default header image is also showing just above it with the tagline and header text still on the default header image.
Blackbam
says:
on 05. September 2012 at 18:23 on clock
Hey there, you seem to use ready templates, which already have built-in header images. But I can give you some advice how you can get it done.
1. In your backend go to: Appearance -> Editor
2. Go probably can see a header.php-file listed below the word "Templates" on the right -> click it.
3. Now you have to read the code - search for the place in the code, where the original header image is embedded.
4. Replace (or better comment it out with /* ... code ... */) and put the Plugin code into this place and save your file.
5. Now you can see your Plugin header images instead of the original one.
Be careful and make sure, you do not delete any code you might need. You cannot update your Theme any more without making this changes again.
Fitguy1789
says:
on 06. September 2012 at 07:05 on clock
What code am i looking for? I looked in the header.php and read the whole code and i dont think any of the codes looked like a code that would be used for header images. This is the only possible code that might be the only possible code that i am looking at..I doubt this is the code that you want me to look for though. <a href="/">
Blackbam
says:
on 06. September 2012 at 14:21 on clock
Hello, the theme you are using is built by some external theme developer. If it is tricky to remove the header image in your Theme you should possibly try another one or alternativly hire some experienced Web developer to recode this part of your theme. You can send the code or login data for your blog to me in a mail (admin@blackbam.at), but I will only do this for free if it is very quick to do.
Fitguy1789
says:
on 07. September 2012 at 07:32 on clock
I will consider changing the theme tomorrow and see what i can get...Appreciate the help btw.
Hannu Hurme
says:
on 11. October 2012 at 14:46 on clock
Hello, Thank you for the wonderful plugin! I have a problem and I'm wondering if it's a lot of work to create a work around. I'm using a header image in a single category and I was hoping it would also show on the individual posts underneath that category as the posts are part of it. This is not the case though and it would be a lot of work to add that same image manually to potentially hundreds of posts. Is there any way to make the posts "inherit" the parent categorys header image?
Blackbam
says:
on 11. October 2012 at 18:47 on clock
Hey Hannu,
there is a way how you could achieve this quite easily. The images for categories are saved as options into your database.
1. Go to your single posts template (or the part of your template which displays single posts)
2. Get the category ID(s) of your post (with get_the_category($post->ID))
3. Check, if this post is inside the desired category
4. Use the following code in your single posts template to get the category image url
5. Display the image as href in an html img tag. Specifiy width and height.
Hope this helps!
Rico
says:
on 12. October 2012 at 15:38 on clock
I want to have a different header (banner) for each category. I am using Thesis Theme and I cannot find the file to replace the header code. Is Thesis different or am I doing something wrong.
Blackbam
says:
on 12. October 2012 at 16:04 on clock
Hello, unfortunatly I cannot check all the themes out there. But I recommend you the following steps to find a solution:
1. Check if you can specifiy header images when editing your category settings. If it is not possible, the Plugin does not work because of other Plugins or unexpectedly modified WordPress installation.
2. It cannot be that hard to find the location in your Themes' files where categories are displayed. Start your search in index.php. Check if category.php or taxonomy.php exists. Just try some different places to insert the chi_display_header(); function.
3. If the wrong images are displayed, the routing of your Theme is customized at this place. See the previous comment: Try to get the category ID in some way and get the category image url directly.
Hope this helps.
Shannon
says:
on 19. October 2012 at 21:59 on clock
I am using wpfolio. Installed and am using a childs theme. In the edit plugins page I am trying to add the code to the .php. There is a message saying I need to make this file writable. How? Thank you, I am about ready to pitch the whole project and give up on wordpress altogether so any help would be greatly appreciated.
Blackbam
says:
on 22. October 2012 at 14:44 on clock
Hello, making a templates' file writable is not problem of the plugin. However you should use a simple ftp-client like "Filezilla" and change a files' rights to 777, if Linux server. Another possibility is to install a WordPress Plugin for using PHP inside some widget, like "Linkable Title and PHP Widget".
Or ask somebody with basic programming abilities.
Shannon
says:
on 23. October 2012 at 20:03 on clock
What is it a problem with? The theme itself?
Blackbam
says:
on 24. October 2012 at 16:52 on clock
Hello, I do not think that it is a Themes' Problem, but a Problem with your Webhost. Check your server configuration, as editing Themes inside WordPress should work, if there are no restrictions by the host.
Mica
says:
on 15. November 2012 at 03:48 on clock
Hello! I downloaded it to my ftp no problem, but in wordpress it doesn't show up in plug ins, nor is "header" under appearance, themes.... I'm not strong in coding so I'm not sure if what I'm doing wrong when trying to activate. Advice? Thanks!
Blackbam
says:
on 15. November 2012 at 10:27 on clock
Hello, did you unzip the Plugin and put it in /wp-content/plugins/ folder? The hierarchy should be /wp-content/plugins/custom-header-images/custom-header-images.php. The most easy way to install the Plugin is to use the auto-installer of WordPress.
The Plugin is hosted at the official WordPress Plugin repository. Try that one instead, as it seems to work for everybody else.
ceah
says:
on 26. November 2012 at 05:53 on clock
Hi, I'm using your header plugin and I was able to put a different image each page. however, my theme is responsive and while my header on the main page resizes, the headers that I added via your plugin don't resize. Is there a way to make those headers resize like my main header? thanks
Blackbam
says:
on 27. November 2012 at 19:54 on clock
Hey,
thats a good question. The reason for this is the following: The images are used with the CSS background-image property, because I wanted to avoid conflicts with different sizes. If you use jQuery or something like that for your Responsiveness, it obviously will not resize background images.
So I recommend you to do the following, its very easy to code:
- Go into the Plugin and search the HTML-code where the image output is (something like <div style="background-image:<?php echo $header_image url; ?>)
- Instead of this you do the following: <div><img src="<?php echo $header_image_url; ?>" alt="" /></div><br />
In the next release of the Plugin I will create an backend option for the output, so you can comfortably change this behaviour. Let me know if it solves the problem!
Mandy
says:
on 19. December 2012 at 01:09 on clock
Hi this is probably a great plug-in but I was disappointed to find out I couldnt specify a page that I wanted the header image to display on, e.g about us, etc It is unclear when picking this plug-in that it only installs header images on pre-determined pages or a generic one for all.
Blackbam
says:
on 20. December 2012 at 00:07 on clock
Hello, sorry but I do not get the problem. At the bottom of each page edit screen you should find a box named "Custom Header Image" (this is possibly displayed below your comments). There you can specifiy a header Image for a post, page, or even a custom post type for example. The default header images on the settings page are only used if you do not specify a concrete one. What exactly are you missing here?
Megan
says:
on 25. January 2013 at 22:01 on clock
Hi, How do you make sure the query object has been loaded correctly? Thanks, Megan
Blackbam
says:
on 28. January 2013 at 01:51 on clock
Hello
this should work with any Theme which is loaded correctly. I use conditional tags and the global variable $post to check if everything has been loaded correctly. If header images are not displaying correctly, you should make sure that global $post is initialized and conditional tags can be used before loading the Plugin images.
Gigi
says:
on 03. February 2013 at 21:02 on clock
Hello, thanks for the great plugin, exactly what I needed. One question though, on some pages I have a lot of images, so it take time to load header image, say 3seconds, can I make changes so it will load first? Thank you :)
Blackbam
says:
on 04. February 2013 at 00:37 on clock
Hello, the header image is exactly loaded as soon as the html-code reaches the position of this image. As header images are used to be called in the header. However, loading can still take some time.
So you could do the following: Put the chi_display_header(); -function into a wrapper at the very top of your page (right after the opening html-tag). This wrapper should have the following CSS-attributes:
position:absolute;
margin-right:-999999px;
There should be no problem with using the function chi_display_header(); more than 1 time.
I am not sure if this works (especially conditional tags must work where you place the function), but you should try it. Furthermore you could check if a tutorial like this helps: http://perishablepress.com/3-ways-preload-images-css-javascript-ajax/.
If you are a programmer you could also rewrite the Plugin to preload images, which might be a feature I could implement in the future.
K
says:
on 03. March 2013 at 05:43 on clock
This code worked fine for me and I was able to center it with standard HTML tags. The only issue I am having now is that my blog is responsive and now only the header image does not adjust for mobile and tablets. Any advice?
Blackbam
says:
on 03. March 2013 at 13:19 on clock
Oh thats a really good point, thank you for advising me on this. In the next version I will include custom output methods, so it should be more simple to integrate with responsive layouts.
But if you do not want to wait, go to line 479 in the Plugin code and change the output so it will fit your needs. Just use the variables $width, $height, and $header_image_url and change the output to your needs.
Just remember to adjust it again if you update to the next version of the Plugin, where the Plugin will support this function nativley.
K
says:
on 07. March 2013 at 09:28 on clock
Any chance the plugin will be updated so header image will be responsive?!#!
K
says:
on 07. March 2013 at 09:30 on clock
Not sure if my last message came through ... I did see your comment "Just use the variables $width, $height, and $header_image_url and change the output to your needs. " but not exactly sure what you want me to replace? The original header size right now is 1010 x 204 px. Would LOVE to get clarification, this is the best plugin I have found but without responsive feature, not of much help! Please update or clarify what to do! Thank you! xoxo
Andrew
says:
on 11. March 2013 at 22:42 on clock
Great plugin and instructions, got it working no problem at all thanks :-)
One question though, in areas where you are using a custom plugin can you also use a custom URL so for example a custom image for a category will link to the category homepage?
I may have set it up up slightly wrong as the theme I was modifying already had image header wrapped in a homepage link - maybe I should have removed the link and added links to the images in the media library?
Blackbam
says:
on 14. March 2013 at 11:34 on clock
@K: Hello again, I mean you should edit the source-code in the Plugins' PHP file until the next version of the Plugin is released. The code you should edit is in line 479 of the Plugin. Just some standard HTML with PHP output.
Blackbam
says:
on 14. March 2013 at 11:40 on clock
Hello, currently you cannot link the images from inside the Plugin, but I will probably implement this in some days.
You should just try if it works well enough with the built-in function for links in your theme, but it may cause problems as it will behave differently as the Plugin for some cases, I suppose.
Adam
says:
on 19. March 2013 at 20:02 on clock
Okay, my two different header images are different sizes. One is very big and one is very small. So if I set the header size in the admin settings>custom header images settings...the pages that will display the smaller image have huge amount of white spacing that doesn't need to be there because the header area is displaying the same size as the bigger header image. How can I fix this?
Blackbam
says:
on 20. March 2013 at 22:38 on clock
Hello Adam, if I understood this correctly, you just have to put two different functions on the two different pages e.g.
Page 1 PHP: if(function_exists('chi_display_header')) { chi_display_header(1000,500); }
Page 2 PHP: if(function_exists('chi_display_header')) { chi_display_header(100,50); }
Adjust this to your needs. Just use conditional tags to use the right function. The new version of the Plugin is in beta phase (just some manuell testing left), if you wait for a few days, you can use the features of the new Plugin version to customize the output further.
sathish
says:
on 28. March 2013 at 09:17 on clock
how to give Background colour for custom header plugin
JC
says:
on 30. March 2013 at 21:13 on clock
The update to this plugin caused this error...
Plugin could not be activated because it triggered a fatal error.
Parse error: syntax error, unexpected '[' in /home/****/public_html/wp-content/plugins/custom-header-images/custom-header-images.php on line 692
Any suggestions on how to fix much welcomed.
Thankyou.
Blackbam
says:
on 31. March 2013 at 02:31 on clock
Hello I am sorry for the inconveniance. Thank you for pointing me at this! It was a problem with slightly older PHP versions, which did not occur in my testing environment. The problem will be fixed with the next update, which I will upload immediatly.
NOTE: FOR EVERYONE having this problem: Please download the Plugin again and update it to the currently active version in the repository!
K
says:
on 02. April 2013 at 03:48 on clock
Hi, just thought I would stop by and see if there are any new updates to make the header images responsive. I still don't fully understand your previous replies. I have no idea what you want me to type on line 479 so an example would be nice.
Blackbam
says:
on 02. April 2013 at 12:58 on clock
Hey, just download the new version (1.1.1) and forget about what I wrote previously.
1. At the bottom of the settings page you will find a box called "Customize Output".
2. Below this box, click "restore default".
3. Customize the output to your needs, while keeping the important information
4. Do whatever necessary for your Output to be responsive
Let me know if this helps, now!
Al
says:
on 09. April 2013 at 19:48 on clock
Hi,
II see there are the shortcode tags beloiw, but they don;t seem to work when I stick them in the page...nor do I see how I can put the PHP on the pages to get them allow a different image size.
How/where can these be put so I can have my main page as one image at a large image size and the other pages with a different image size?
[image_url] ... The header image URL
[link] ... The header image Link
[width] ... The header image defined width
[height] ... The header image defined height
Blackbam
says:
on 09. April 2013 at 23:28 on clock
Hello Al, you seem to confuse the output with the shorttag.
1. Click "restore default" at the bottom of the Plugin
2. You see the pre-made output of the Plugin now, which you can customize if you want - whenever you run into troubles, you should restore default again and make thinks working in a different way.
Think of [image_url], [link], [width], [height] as "variables", which you can use in your html-code. Actually these special shortcodes are replaced with the correct content by PHPs' str_replace -function in the plugin internally
3. Do not confuse this, with the actual output function of the Plugin. For example you could use the following PHP in your template:
if(function_exists('chi_display_header')) { chi_display_header(1000,200); } for big size images // [width] will be replaced by 1000 and [height] will be replaced by 200 // in the final output, if this line of code is reached. if(function_exists('chi_display_header')) { chi_display_header(500,100); } for small size images // [width] will be replaced by 500 and [height] will be replaced by 100 // in the final output, if this line of code is reached.and so on...
Please let me know if this helps or if you still have problems.
Chris
says:
on 30. April 2013 at 18:06 on clock
Hey man, cool plugin. Glad to see you're still supporting it. I have a question about linking the header images to a URL (so when the user clicks on the image they go to a specific URL). I've checked the box and included the link to the page, but the header does not link to the specified URL.
Did I miss a step somewhere?
Blackbam
says:
on 02. May 2013 at 19:58 on clock
Hello,
you should make sure that the following:
1. Links must be enabled, the link must be correctly specified (if it is working for most of the images, but not for a specific one this might be a bug, please report it)
2. If you use custom output, make sure that you use the [link] shorttag properly in your output - if not, please try again with using custom output and tell me, if this solved the problem - the linking functionality is basically the same as the images functionality, so if the images work, the links should work, too.
Hope this helps.
janet saw
says:
on 21. May 2013 at 06:24 on clock
Brilliant - after weeks of searhing I found this site and plugin. Thank you so much!!!! I've also made a donation and urge others who have fund this useful to do the same, it's more than worth it.
Blackbam
says:
on 21. May 2013 at 13:04 on clock
Thanks a lot I recieved your donation. It is a great motivation to hear about people who value the work on free WordPress Plugins to keep up good work :-)
Leave a comment: