Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Change Footer Element Background on each page

  • Hello,
    On my website each page has a color assigned to it. Example home = yellow, inner page 1 = green and inner page 2 = red.

    I have built a footer and a top bar for my website using elements. It is working perfectly, the background color on it is currently yellow.

    My question is:
    Can I make it so that when a user is on page 1 the footer (ant top bar) background color turns green, and when they are on page 2 it turns red? Would this be css?

    I hope this makes sense.
    Thank you very much.
    R

  • Hi R,

    On my website each page has a color assigned to it. Example home = yellow, inner page 1 = green and inner page 2 = red.

    How did you assign the color to pages?

  • Hi Ying,
    sorry, maybe i didnt explain correctly.

    I didnt “assign” a color. what i mean is that the color i am using mostly for links, callouts, borders, and other highlights is yellow on the home page, page 1 = green and inner page 2 = red.
    I would like my footer background color to change to match the “main” color of each page.
    I hope that makes more sense.
    Thank you.
    R

  • Hi there,

    you could do this with a little CSS and the GP Color Pallet.
    For example:

    1. go to Customizer > Colors and add a new color , lets call it: main-color and set it to the color for your homepage eg. #ffff00.

    For reference GP will print the following CSS on your site to register that color:

    
    :root {
        --main-color: #ffff00;
    }
    

    2. Now assign this color to those elements on your site.
    Which will currently apply to ALL pages of the site.

    3. Now create additional colors in your pallet for the alternative colors eg.

    main-alt-1 and with the color #00ff00
    main-alt-2 and with the color #ff0000

    The GP Dynamic CSS for these colors will now be like so:

    
    :root {
        --main-color: #ffff00;
        --main-alt-1: #00ff00;
        --main-alt-2: ##ff0000;
    }
    

    Note that the CSS has the -- prefix, this is auto added by GP and should not be included in the color pallets name. so you enter main-colour and GP prints --main-color.

    4. Now comes the custom CSS part where we will swap the value of --main-color with an alternative color depending on what page it is on.

    First we need a way to select the specific page in our CSS and that we can use one of the WP body classes.
    View the page and Right Click and Insepct the page to open the browser developers tools.
    In the dev tools elements tab, look for the body tag where you will find the body classes. For reference and example see here:

    https://app.screencast.com/YVoWDUdlJS8Lh

    For this example we will use my page-id-178 class for our CSS selector like so to swap the --main-color value for the --main-alt-1 value:

    
    .page-id-178 {
        --main-color: var(--main-alt-1);
    }
    

    If you need assistance with swapping colors for specific pages, share us some links to your site and we can assist with the specific CSS.

  • Hi David,
    I think I understand all of this, amazing. I like this idea a lot as it seems I will be able to use it for all the elements on the page.
    I will try this out over the next few days and let you know how it went.
    Thank you very much. Amazing support as always.
    R

  • I started to try it out and it is working perfectly. Took me about 5 mins to start making changes.
    Thank you very much. you guys are awesome.
    R

  • Super happy to hear that!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.