• Hi there, I would like to modify the images in the banner section. I was told to change them from the dashboard – appearance – header, but what if I want to change them manually?
    I have created a child theme folder and I have created an image->header folder too. I have added my new image there, but the banner hasn’t change. Any suggestion please?
    thanks

Viewing 15 replies - 16 through 30 (of 32 total)
  • You need to use something like:

    register_default_headers( array(
    		'wheel' => array(
    			'url' => '%s/images/headers/image1.jpg',
    			'thumbnail_url' => '%s/images/headers/image1-thumbnail.jpg',
    			'description' => __( 'name_of_image_here', 'twentyeleven' )
    		)

    Thread Starter giec

    (@giec)

    uhm, I think something went wrong. I have created another functions.php file in my /public_html/andys/wp/wp-content/themes/twentyeleven-child, and replaced the register_default_headers to the following

    register_default_headers( array(
    		'wheel' => array(
    			'url' => '%s/images/headers/andy_background.jpg',
    			'thumbnail_url' => '%s/images/headers/andy_background.jpg',
    			/* translators: header image description */
    			'description' => __( 'andy_background', 'twentyeleven' )
    		),
    		'shore' => array(
    			'url' => '%s/images/headers/andy_background_1.jpg',
    			'thumbnail_url' => '%s/images/headers/andy_background_1.jpg',
    			/* translators: header image description */
    			'description' => __( 'andy_background_1', 'twentyeleven' )
    		)
    	) );
    }

    If you look at my site now though you nget the following error http://andys.antonioborrillo.co.uk/wp/?page_id=20. It’s all gone bananas…

    Have a look at the Twenty Eleven’s functions,php file. See how its register_default_headers() is wrapped inside a function (twentyeleven_setup() ) that is then added to the after_setup_theme action hook? You need to do something similar in the child. Wrap the header banners code inside a function called something like my_headers() and then use add_action( 'after_setup_theme', 'my_headers' ); to get the function to run.

    Thread Starter giec

    (@giec)

    But I don’t get this. I mean, I thought I could reuse the functions.php file in my own folder (/public_html/andys/wp/wp-content/themes/twentyeleven-child), change the reference to the pictures and the theme and run the function. Is that because my twentyeleven-child folder doestn’ have all the necessary php files in it?

    I thought I could reuse the functions.php file in my own folder

    Nooo! You have to start with a blank functions.php file in the child theme and then just add your new or custom functions to that file.

    Thread Starter giec

    (@giec)

    you mean my functions.php to go into /public_html/andys/wp/wp-content/themes/twentyeleven-child should look like this;

    <?php
    
    my_headers ( array(
    		'wheel' => array(
    			'url' => '%s/images/headers/andy_background.jpg',
    			'thumbnail_url' => '%s/images/headers/wheel-thumbnail.jpg',
    			/* translators: header image description */
    			'description' => __( 'Wheel', 'twentyeleven' )
    		),
    		'shore' => array(
    			'url' => '%s/images/headers/andy_background_1.jpg',
    			'thumbnail_url' => '%s/images/headers/shore-thumbnail.jpg',
    			/* translators: header image description */
    			'description' => __( 'Shore', 'twentyeleven' )
    		)
    	) );
    add_action( 'after_setup_theme', 'my_headers' );
    ?>

    As said I don’t do php so not sure whether the syntax is correct
    thanks

    Yes! You’ve got it!

    Thread Starter giec

    (@giec)

    one more thing esmi, I think the syntax is wrong. My header is a function, how about this version then:

    <?php
    
    function my_headers(){
    register_default_headers ( array(
    		'image1' => array(
    			'url' => '%s/images/headers/andy_background.jpg',
    			'thumbnail_url' => '%s/images/headers/andy_background_thumb.jpg',
    			/* translators: header image description */
    			'description' => __( 'Image description', 'twentyeleven-child' )
    		),
    		'image2' => array(
    			'url' => '%s/images/headers/andy_background_1.jpg',
    			'thumbnail_url' => '%s/images/headers/andy_background_1_thumb.jpg',
    			/* translators: header image description */
    			'description' => __( 'Shore', 'twentyeleven-child' )
    		)
    	) );
    }
    add_action( 'after_setup_theme', 'my_headers' );
    ?>

    Oops – I missed that, You’re right. You need to use function my_headers().

    Thread Starter giec

    (@giec)

    uhm, it doesn’t work. There is actually something peculiar happening. The original images are still all there. I managed to load my images (even if oddly enough I had to use an absolute path in the php script?!)If you refresh a good 7-8 times http://andys.antonioborrillo.co.uk/wp/?page_id=20 you will still see the default images.How do I get rid of them? we are getting there : – )

    First. can you see the new images in the back end of your site in Admin -> Header?

    Thread Starter giec

    (@giec)

    I actually ca, although for some odd reasons they are not thumbnails but full pictures, but they are there yes

    You need to upload a second set of smaller banner thumbnails that are 230 x 66.

    Thread Starter giec

    (@giec)

    well I am not too worried about the thumbnails to be honest, what worries me is the fact that I need to get rid of the default images that are stil there. How do I do that, can I do it from the dashboard or do I have to do it on the php script?
    thanks

    Hi Guys,

    'url' => '%s/

    The %s is returning the parents directory and not the child themes directory, that is why the code is not working.

    You need to upload a second set of smaller banner thumbnails that are 230 x 66.

    If you want to use this code you must do as esmi said, image names should be lowercase, no spaces, and every header must have a thumbnail
    storm.png and storm-thumbnail.png
    storm-chaser.png and storm-chaser-thumbnail.png

    width can be altered to display a bigger thumbnail if you want, height should be proportional, just re-size the headers 230px wide and save as with the -thumbnail added!

    Making the thumbnails takes a few minutes and makes all the difference.

    Maybe I can help out here, have a look at this code:
    http://pastebin.com/56X9mX9R

    First it will remove the parent themes images.

    unregister_default_headers

    Next there is a nice little function I created:

    • it will look in the child theme’s folder for /images/headers/
    • loop through the files
    • find images with -thumbnail like storm-thumbnail.png
    • load the images into an array, path, thumbnail, name etc:
    • name is first cased storm-chaser becomes Storm Chaser for the title
    • Register the new headers

    It is really nice because you only need to add the headers and thumbnails to the folder, you do not have to write the code to register them the function will do all that for you!

    This would make a nice addition to your functions library!

    HTH

    David

Viewing 15 replies - 16 through 30 (of 32 total)
  • The topic ‘probelms with banner images’ is closed to new replies.