• Resolved erobs16x

    (@erobs16x)


    Hello,

    Does anyone know if it’s possible to change the background color for specific posts?

    For example:

    Post A would have a background color of “Red”
    Post B would have a background color of “Black”
    Post C would have a background color of “Yellow”
    etc.

    Do I have to make a Post Template for each one? If so, how would I get started on doing such a thing?

    Appreciate the help in advanced!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Each post has a unique custom class which you can target with CSS in your child theme. It follows the format: postid-NN where NN is the post ID.

    You can find the post ID in the address bar of your browser when editing the post, or by looking at the body tag when viewing the browser source or using a web inspector.

    For example, this post has the ID 51:

    https://pictoricodemo.wordpress.com/2011/07/07/morning-tea/

    And you can target its background colour like this:

    .postid-51 {
      background-color: red;
    }

    Replace red with whatever colour code you prefer.

    If you want to change multiple posts’ background to the same colour, you can add them to the same CSS declaration, separated by commas. So for example:

    .postid-51, .postid-60, .postid-73 {
      background-color: red;
    }

    Let me know how it goes.

    Thread Starter erobs16x

    (@erobs16x)

    You’re the best Kathryn, worked perfect only difference was the target name set up,

    .post-43 {
    background-color: #000;
    }

    thank you!

    Ah, you’re targeting the article element background instead of the body background class – the class names are slightly different. Glad that did the trick!

    I could use some clarification on this. Is there a specific place this should go? I am using ‘Hero’ theme, which has an area that is available specifically for throwing some custom CSS in. When I add the “.post” command, it changes my ‘featured posts’ area on my page, but does not effect the main post itself, so perhaps I’m not entering it in the correct area.

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

The topic ‘Change Specific Post Background Colors’ is closed to new replies.