Random Header Image- Change the Defaults

  • ty502100

    #2289

    I spent awhile last night scouring this forum to try to figure out how to change the default images provided with this amazing theme so that I can have a set of however many images I wanted to be chosen from. I couldnt find the answer so i went to bed and approached this again this morning, Im pretty sure with a fresh start I was able to figure it out. Wanted to share what I did because I saw alot of people asking teh question and I didnt see any answers.

    Head over to your editor and find the ‘Theme Functions’ section and open the “fucntions.php” file in your editor.

    I dont have a fancy word editor as Im very new to php and havent gone all out on this yet so I dont knwo exactly what line it is on. However just scroll down a bit until you get to this section of code. Youll notice i simply copied the snippet of code and replaced a few keywords with the right oens I wanted to use in teh Turtle.Jpg one, worked liek a charm. I did of course make sure every dimension was correct and I made a thumbnail and uploaded it as well. This may be longer and more tedious then others could do it in but it got teh job done and I was rackign my brain last night trying to get this to work with. Liek I said, Im fairly noob at this.

    if (!function_exists( 'graphene_get_default_headers' ) ) {
    function graphene_get_default_headers() {
    return array( 'Schematic' => array( 'url' => '%s/images/headers/schematic.jpg',
    'thumbnail_url' => '%s/images/headers/schematic-thumb.jpg',
    /* translators: header image description */
    'description' => __( 'Header image by Syahir Hakim', 'graphene' ) ),
    'Flow' => array( 'url' => '%s/images/headers/flow.jpg',
    'thumbnail_url' => '%s/images/headers/flow-thumb.jpg',
    /* translators: header image description */
    'description' => __( ' image by Quantin Houyoux at sxc.hu', 'graphene' ) ),
    'Fluid' => array( 'url' => '%s/images/headers/fluid.jpg',
    'thumbnail_url' => '%s/images/headers/fluid-thumb.jpg',
    /* translators: header image description */
    'description' => __( 'image by Ilco at sxc.hu', 'graphene' ) ),
    'Turtles' => array( 'url' => '%s/images/headers/Turtles.jpg',
    'thumbnail_url' => '%s/images/headers/Turtles-thumb.jpg',
    /* translators: header image description */
    'description' => __( 'Turtles', 'Hussex' ) ),
    'Techno' => array( 'url' => '%s/images/headers/techno.jpg',
    'thumbnail_url' => '%s/images/headers/techno-thumb.jpg',
    /* translators: header image description */
    'description' => __( 'Header image cropped from image by Ilco at sxc.hu', 'graphene' ) ),
    'Fireworks' => array( 'url' => '%s/images/headers/fireworks.jpg',
    'thumbnail_url' => '%s/images/headers/fireworks-thumb.jpg',
    /* translators: header image description */
    'description' => __( 'Header image cropped from image by Ilco at sxc.hu', 'graphene' ) ),
    'Nebula' => array( 'url' => '%s/images/headers/nebula.jpg',
    'thumbnail_url' => '%s/images/headers/nebula-thumb.jpg',
    /* translators: header image description */
    'description' => __( 'Header image cropped from image by Ilco at sxc.hu', 'graphene' ) ),
    'Sparkle' => array( 'url' => '%s/images/headers/sparkle.jpg',
    'thumbnail_url' => '%s/images/headers/sparkle-thumb.jpg',
    /* translators: header image description */
    'description' => __( 'Header image cropped from image by Ilco at sxc.hu', 'graphene' ) ),
    );
    }
    }
    Mod

    Kenneth John Odle

    #19633

    Please put code between backticks (`).

    You should do this in a child theme, however. Any modifications you make to Graphene core files will be lost in the next update. You can find out how to make a child theme in the Graphene wiki, which is here:

    http://wiki.khairul-syahir.com/graphene-theme/wiki/Customisation_using_a_child_theme

    Did you do this so you can take advantage of the “Random: Show a different image on each page” option?

    I dont have a fancy word editor

    I would suggest Notepadd++ for Windoze, which is free and shows you the line numbers. Very handy. You can get it here. The Mac version, Macpad++, is here.

    Thanks for sharing,

    Ken

    ty502100

    #19634

    sorry for the not having backticks thing, know i know and will do that going forward!

    thx for the word++ thingie, downloaded it and installing it now. Looks much easier to work in and I can get that line number i see everyone talking about.

    Ya I wanted it to show a random header everytime it loaded anything. Probably like everyone else I just assumed that if i threw the images in the right folder it would work but I was so wrong.

    I just bookmarked that wiki page you provided, imma read through it but I am very new to this php stuff and its a bit confusing, for now Im going to go with what I see works but obviously from what yoru saying you are right I need to learn how to do child themes and Ill be reading into that shortly.


    From what i gather so far I do have a quick questuion maybe you can clarify:

    “This is a special WordPress-recognised template file. It will be automatically loaded way before any other template files is loaded. It’s used for a lot of purposes, such as defining new PHP function and setting up certain features for the theme.

    This file is optional. Your child theme can work wihout this file, but if it is present, it will be loaded automatically. Unlike the other template files, when this file exists in your child theme, WordPress will load the child theme’s functions.php file first, and then the parent theme’s functions.php file. This means that both the functions.php file will be loaded. That is the reason why you should not copy the entire codes from the parent theme’s functions.php file.”

    So if I make a new child theme for the functions.php and then I go and remove the code I put in the above post from the default functions and add just that code to the new child theme function then it will basically just be like merging the two sets of codes together, however when you update the theme I will retain my set of code through the update, is that correct?

    Mod

    Kenneth John Odle

    #19635

    Yes, basically. Any new or updated functions should go in the child theme’s functions.php file.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.