Troubleshooting why custom CSS is failing to load on a specific page in WordPress

I've been attempting to modify some CSS for a specific Wordpress page by adding .page-id-# before the new CSS rule, but for some reason, it's not working. I've tried various selectors, using !important, switching browsers, checking the ID, and testing on different pages, but the custom CSS doesn't seem to load.

For example, in the code snippet below, the text on page 2 should be blue instead of red, but the custom CSS isn't loading properly, so it remains red. Am I overlooking something obvious?

Page 1 -------------------------------

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="XAMPP is an easy to install Apache distribution containing MariaDB, PHP and Perl." />
    <meta name="keywords" content="xampp, apache, php, perl, mariadb, open source distribution" />

    <link href="wp-content/themes/testing/style.css" rel="stylesheet" type="text/css" />

    <?php
    wp_head();
    ?>
  </head>


  <body>

  
    <div class="change_colour">Hello</div>
    <div>
    <a href="http://localhost:8080/testing/?page_id=2">Page link</a></div>

  </body>

</html>

Page 2-----------------------------

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="XAMPP is an easy to install Apache distribution containing MariaDB, PHP and Perl." />
    <meta name="keywords" content="xampp, apache, php, perl, mariadb, open source distribution" />

    <link href="wp-content/themes/testing/style.css" rel="stylesheet" type="text/css" />

    <?php
    wp_head();
    ?>



  </head>



  <body>

  
    <div class="change_colour">Hello</div>
    

  </body>

</html>

CSS------------------------

/*
Theme Name: Testing
Text Domain: Testing
Version: 1.0
Decription: 
Tags: 
Author: Jonny

*/


.change_colour {
    color: red;
}

.page-id-2 .change_colour {
    color: blue;
}

Answer №1

In order to customize the styling for a specific page on your website, you will need to include <?php body_class(); ?> within the opening body tag of your HTML code. After doing this, inspect the page and look for the unique .page-id-** class in the body tag. You can then write CSS rules based on this class to style the page according to your preferences.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="XAMPP is an easy to install Apache distribution containing MariaDB, PHP and Perl." />
    <meta name="keywords" content="xampp, apache, php, perl, mariadb, open source distribution" />
    <link href="wp-content/themes/testing/style.css" rel="stylesheet" type="text/css" />
    <?php
    wp_head();
    ?>
  </head>
  <body <?php body_class(); ?> >
    <div class="change_colour">Hello</div>
    <div>
    <a href="http://localhost:8080/testing/?page_id=2">Page link</a></div>
  </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I prevent an endless loop in jQuery?

Look at the code snippet below: function myFunction(z){ if(z == 1){ $(".cloud").each(function(index, element) { if(!$(this).attr('id')){ $(this).css("left", -20+'%'); $(this).next('a').css ...

Tips for creating a new line in PHP when the value includes a comma

I am struggling to format information that includes commas into new lines. The current output I have is shown in the current display. I would like to display it with each comma creating a new line automatically. Below is my current code: <tr> <td ...

Although the xpath simulates a click on the button, it does not actually perform any action

I've been diligently working on an automation test suite for a web application that can be quite temperamental. Following a recent UI update, I decided to run some tests to ensure the GUI, buttons, and xpaths were functioning as expected. The night b ...

Encountering an error when attempting to switch to an IFrame using Selenium in C#

When attempting to switch to the iframe, I encountered a "No Such element exception". <div class="panel1" id="list_container" style="height: 181px;"> <div class="control" id="FilteredDashboardList"> <div class="splitter h ...

Establishing the destination for an onclick event to a designated spot

I have divided my body content into two parts. The left side contains a map and buttons, where clicking on a button displays results from Arad.php in another window. How can I target the second half (split right) of my body? <body> <div cla ...

The issue of the keyboard disappearing on Chrome for Android while switching between different input

Issue with Input Switching on Chrome for Android I am facing difficulty when trying to switch between two input fields. The HTML code is as follows: <input type="text"/> <input type="text"/> When I enter text in the first input and click on ...

Using static typing in Visual Studio for Angular HTML

Is there a tool that can validate HTML and provide intellisense similar to TypeScript? I'm looking for something that can detect errors when using non-existent directives or undeclared scope properties, similar to how TypeScript handles compilation er ...

Upon transitioning to Bootstrap 4, the grid columns automatically wrap

I currently have a table-like display created using the bootstrap grid classes. The body rows on this table are filled dynamically with JavaScript. Depending on the application state, the table is either hidden or shown. I have two divs, one with an ID con ...

Sometimes the data-autoplay feature does not function properly in jQueryfullPage.js

I am in the process of developing an HTML page using jQueryfullPage.js. Within this page, I have incorporated 17 videos across 17 different sections. These videos are presented as YouTube iframes with a data-autoplay attribute. Overall, everything is fun ...

Navigate to the homepage section using a smooth jQuery animation

I am looking to implement a scrolling feature on the homepage section using jquery. The challenge is that I want the scrolling to work regardless of the page I am currently on. Here is the HTML code snippet: <ul> <li class="nav-item active"> ...

What is the best way to access the methods in the "parent" class?

I am facing a situation where I have an object with fieldsCreators that hold creator methods for each field. The dilemma is how to call the creator method inside fieldsCreators as shown below: var obj={ creator:function(ch) { .... .. ...

The effect of iPad screen orientation on CSS styling

Exploring orientation testing using CSS for iPad. Below is the code snippet from the CSS file: @media only screen and (device-width:768px) and(orientation:portrait) { body { background: green; } } @media only screen and (device-width:768px) and(orient ...

unable to press the electron button

I am currently working on a project that involves connecting PCs together for screencasting. While following an online coding tutorial, I encountered an issue with clicking the button to generate the ID code. Here is the code snippet from app.js: // Code ...

Creating a persistent hover effect

Utilizing primarily CSS, along with background images and adjacent selectors, I am creating a page that displays unique human-readable text information when the user hovers over horizontally stacked images. The textual information is presented in a div on ...

Photographs featuring a ripple effect in the columns of Zurb's Foundation framework

Working on a WordPress site using the Foundation 6 CSS framework, I have a design with a row containing two large-6 columns, each filled with an image featuring a wave shape. Check out the image I've linked below. View the row with 2 columns I' ...

Navigate through a filtered list of parent items with the use of cursor arrows in AngularJS

My form contains an input with a dropdown, where I display JSON data like this: { "title": "Parent #1", "child" : [ {"title": "Child ##1"}, {"title": "Child ##2"}, {"title": "Child ##3"}, {"title": "Child ##4"} ...

A table featuring two tbody sections positioned side by side within the table structure, with the thead located at the top

My goal is to design an HTML table layout resembling the following: Left part | Right part | Remove row? ------------------------------------------- 1 [input] [input] Y/N 2 [input] [input] Y/N 3 [input] [inpu ...

Is there a way to implement an onclick event for every iframe within a document using jquery?

I have a webpage containing two iframes that can be switched using a selector. My goal is to implement an onclick event that will trigger a URL for specific <rect> elements within the iframes. After reading a helpful post on accessing iframe childr ...

Button color changes upon submission of form

Can anyone help me figure out how to change the color of a submit button after a form submission using Twitter Bootstrap 3? I have a form with multiple buttons serving as filters for my product page, but I can't seem to change the color of the selecte ...

Aligning text to the center and having it displayed on either side of it

Hey there, I need help with the following: <div id='1'></div> <div id='2'></div> <div id='3'></div> I want to place a single word into each div. The width of each div should be ...