How to Change Background Color in WordPress Pages

Home » Snippets » How to Change Background Color in WordPress Pages
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Customizing the background color of your WordPress site’s pages can be an easy way to make your website stand out from others. Whether you’re looking to match your brand’s color scheme or simply want to add a pop of color to your site, changing the background color can be a quick and effective solution. In this article, we’ll guide you through the step-by-step process of changing the background color of your WordPress page. Let’s begin!

					function wpturbo_change_page_background() {
  ?>
  <style type="text/css">
    body.page {
      background-color: #ffcc00; /* replace with your desired background color */
    }
  </style>
  <?php
}
add_action( 'wp_head', 'wpturbo_change_page_background' );
				

In this article, we will learn how to change the background color of a specific page in WordPress. We will do this by modifying the CSS of a page with the use of a WordPress function.

First, we define a new function called wpturbo_change_page_background(). Inside the function, we use PHP to display CSS to change the background color. We specify the color by setting the value of the background-color property to the desired hexadecimal color code. In this case, we set it to #ffcc00, but you can replace it with any color code you prefer to use.

<style type="text/css">
    body.page {
      background-color: #ffcc00; /* replace with your desired background color */
    }
</style>

We use the .page class to target the specific page we want to change the background color. You can change the CSS selector to target a different element of the page by changing the value before .page.

Lastly, we hook our function into the wp_head action of WordPress. This ensures that our function is executed and the CSS is displayed within the head section of the page when we load the webpage.

add_action( 'wp_head', 'wpturbo_change_page_background' );

With these steps done, you should now be able to change the background color of any page in WordPress by using the wpturbo_change_page_background() function and modifying its background-color CSS property value.

Register an account to save your snippets or go Pro to get more features.