As we all know, the twenty-eleven theme comes with a random banner feature which, if the site visitor clicks it, takes him to the home page.

So there could be quite a few different images for the banner, but they all take you to the same URL when you click them.

What I would like to have is that each banner image will have its own URL.

How do I accomplish this?

  • 1
    even if you could override the URL, how would you propose to edit/add/change the urls from the backend? – Tom J Nowell Apr 13 '12 at 17:14
  • @Tom J Nowell That's an excellent question and +1 for that. I, of course, prefer some sort of a plugin that will allow me to change the URLs from the backend, but if something like this isn't already available, then I will compromise on hacking the child theme's PHP files. Any idea which file I should be looking at? – ef2011 Apr 13 '12 at 19:07

I recommend you register a post type called 'header_slide' and use the featured image of said posts as the banner. Do a query with a maximum of 1 post per page and display the banner, and add the url as a custom field.

Something similar to this:

$q = new WP_Query(array(
    'post_type' => 'header_slide',
    'posts_per_page' => 1,
    'orderby ' => 'rand'

            $url = get_post_meta($post->ID,'custom_header_link',true);
                $url = home_url();
            echo '<a href="'.$url.'">';
            the_post_thumbnail(array(920,200)); // adjust numbers to fit desired size
            echo '</a>';
} else {
    // hmm no header slides were found, ABORT!!!!!! or maybe display a default


To generate the code for registering the header_slide post type, go here:


Answer the questions and it will generate a chunk of code for you at the end, put that code into your themes functions.php, and make sure it supports custom fields and featured images/post thumbnails

  • What a great detailed answer. If this also allows editing the URL from the backend, then I couldn't have expected a better answer than this. Now, I do have a header plugin installed which associates each page with a specific banner. Will this get in the way? BTW, my own grepping found that the URL is currently fixed at header.php around line #74. – ef2011 Apr 16 '12 at 12:59
  • This solution is separate from your header plugin. You should have made us aware you already had a plugin when you asked the question. My solution is self contained, and separate – Tom J Nowell Apr 16 '12 at 13:17
  • Didn't notice your link to header.php, I must point out that whatever you do, it will not be using the standard wordpress header banner API call – Tom J Nowell Apr 16 '12 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.