Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

After creating a child theme which is made of style.css only (base on twentyeleven), the time has come to replace the images.

I found this great tip for accomplishing this by hacking the functions in twentyeleven but my main concern is minimizing work after a WordPress update.

I thought of simply replacing the images in /wp-content/themes/twentyeleven/images/headers (while keeping the original names as came with twentyeleven) but is this better?

It looks like either way I will have re-apply my customizations after updating WordPress in the future.

Is there a way to replace the 8 images, for a child theme, and still maintain the changes after an update?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

I am never sure about 'optimal approach' - however, I am using this in the functions.php in a child theme of Twenty Eleven

//deregister the header images of Twenty Eleven, and register a few new RAW header images//
add_action( 'after_setup_theme', 'raw_theme_header_images', 11 ); 

function raw_theme_header_images() {
unregister_default_headers( array( 'wheel', 'shore', 'trolley', 'pine-cone', 'chessboard', 'lanterns', 'willow', 'hanoi' ) ); 
$folder = get_stylesheet_directory_uri();
register_default_headers( array(
    'coleslaw' => array(
        'url' => $folder.'/images/headers/coleslaw.jpg',
        'thumbnail_url' => $folder.'/images/headers/coleslaw-thumb.jpg',
        /* translators: header image description */
        'description' => __( 'Coleslaw', 'twentyeleven' )
    ),
    'tomato_and_sprouts' => array(
        'url' => $folder.'/images/headers/tomato_and_sprouts.jpg',
        'thumbnail_url' => $folder.'/images/headers/tomato_and_sprouts-thumb.jpg',
        /* translators: header image description */
        'description' => __( 'Tomato and Sprouts', 'twentyeleven' )
    )
)
);
}

the new images are in an /images folder in the child theme.

share|improve this answer
    
+1. Using unregister_default_headers() is absolutely the correct approach. –  Chip Bennett Feb 1 '12 at 16:44
    
@Michael Thanks +1. This looks similar to the solution in the link. Do I understand correctly from your answer that this solution doesn't modify any php file in the original twentyeleven and the above goes is only new code that goes into the child's directory? –  ef2011 Feb 1 '12 at 17:17
    
correct - this all happens in the child theme's functions.php. –  Michael Feb 1 '12 at 18:17
    
I'm worried about possible future additions to the images with an upgrade => the list of files are hardcoded so still 'vulnerable' in case of an update. Another options might be to empty $_wp_default_headers. You could opt for mapping that array with the unregister_default_headers function for future extra code in that function. Any thoughts on that? –  Nanne Mar 11 '12 at 12:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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