How can I incorporate HTML and CSS into the Wordpress editor?

I am currently working with a child theme based on "freestore". ()

My goal is to insert custom content into one of my pages using basic HTML and CSS. Although I have successfully made changes to the CSS styles within the theme's style.css file, I am facing issues when trying to add my own HTML along with CSS for styling purposes.

After creating a page named 'home' and inserting my HTML code through the WordPress tinymce text editor, I encountered difficulties applying the CSS from my style.css file. Inline styling does work, but I prefer external stylesheets for better organization.

For instance, in the WordPress text editor, I would include the following line:

<div id="cssTest">TEXT</div>

To style this element in my style.css file, I would write:

#cssTest {
    background-color: red;
}

However, the CSS rules are not being applied. On the other hand, adding inline styles directly in the HTML editor works smoothly:

<div id="cssTest" style="background-color: red;">TEXT</div>

My question is as follows:

  1. How can I ensure that my styles are applied using an external stylesheet?
  2. Is it advisable to create a custom template for the page and insert the HTML there instead?

Answer №1

To ensure that the child theme's style.css includes the line Text Domain: freestore-child parentthemename-child, you can verify it manually. Any additional css id or class elements you introduce will be applied as well.

A recommended approach is to establish a custom.css file and include it in your child theme's functions.php using the wp_enqueue_style function.

I personally advocate for creating page templates tailored for specific pages such as the homepage, as I believe it contributes to better organization and efficiency.

Answer №2

It is possible that a CSS rule from your original theme has higher specificity than the rule you are attempting to apply. To investigate this, use browser tools to inspect the element and determine which CSS rule is being applied.

For instance, if the existing rule looks like

.content main .section_1 .gxt1 {
  background-color: black;
}

, you will need to override it with a rule of even higher specificity, such as

.content main .section_1 .gxt1 #cssTest {
  background-color: red;
}

If the original rule includes an !important declaration, you must also use !important in your overriding rule. For example, to overwrite

.content main .section_1 .gxt1 {
  background-color: black !important;
}

, you would have to do something like

.content main .section_1 .gxt1 #cssTest {
  background-color: red !important;
}

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

Maintain the same UI appearance when the checkbox state is altered

<input type="checkbox" [(ngModel)]="rowData.is_permitted" (change)="changeStatus()"> changeStatus() { rowData.is_permitted = true; } When I uncheck the checkbox but conditionally want to select it again, the flag is updated but does not affect the ...

What is the best way to stick a div to the top of another div?

I'm attempting to have the white div appear on top of the grey div, rather than underneath it as shown in the screenshot. https://i.sstatic.net/UYYOt.png This layout is being built using Bootstrap 4. .form-login { text-align: center; back ...

Displaying today's date in a date picker on an HTML 5 form

Is there a way to set the current date as a placeholder in an HTML 5 form using the code below? Date: <input type="date" placeholder="mm/dd/yyyy" name="date" /> ...

Ensuring only one group is open at a time in jQuery when a new group is opened

I need assistance in getting this functionality to work properly. My goal is to have only the clicked group open, while closing all others that are currently open. Here's a specific example of what I am trying to achieve: var accordionsMenu = $(&apo ...

Closing the Bootstrap 5 Navbar on Click Event

I'm not very familiar with Bootstrap and I came across this code online that involves javascript in html, which I don't fully understand. I want to make the hamburger menu close automatically after selecting an item in the navigation bar, especia ...

I need either XPATH or CSS to target a specific checkbox within a list of checkboxes wrapped in span tags

I'm trying to find the XPATH or CSS locator for a checkbox in an HTML span tag that has a label with specific text, like "Allow gender mismatch". I can locate the label using XPATH, but I'm not sure how to target the input tag so I can click on t ...

"Select2 dropdown fails to function properly upon returning to the page using the browser's

I've encountered an issue while working on a search page with Select2 dropdowns. Everything functions smoothly upon the initial page load, however, problems arise when a user performs a search, hits the browser back button, and then revisits the page. ...

Using Selenium in Java to extract text from an h1 tag

Although I am familiar with the method .getAttribute("innerHTML") for retrieving the value of a h1 tag, my HTML structure is a bit different: https://i.sstatic.net/RVaMM.png While I am able to locate the h1 tag, I am facing difficulty in accessing its inn ...

having trouble retrieving information from the input field

I'm having trouble retrieving the user's input from the input field, can someone assist me with this issue? I can't seem to identify what the problem is here. var ftemp = document.getElementById("Farenheit").value; <td> <i ...

Utilizing JSON data retrieved from an API to populate a dropdown menu in HTML

When making a request to an API, I encountered the following error: https://i.sstatic.net/v6PVt.jpg Can anyone advise me on how to insert this into an html select field using jquery ajax? I want it to look something like this: <select> <o ...

Browse through the chosen row information on a separate page with the help of angularJS

Hey there, I have a requirement to show the details of a selected row in the next page. In the first page, I am only displaying the name and city fields, and the rest will be visible after clicking a button. Here is my HTML page: <!DOCTYPE html> &l ...

What is the reason behind utilities.scss taking precedence over styles.scss and local scss files?

After defining the mt-5 class in both my component's .scss file and the root styles.scss, I noticed that they were both overwritten by _utilities.scss. This left me wondering why this was happening. https://i.sstatic.net/idnze.png https://i.sstatic.n ...

Why do style assignments lose their motion when executed right after being made?

If you take a look at this specific fiddle in Webkit, you will see exactly what I am referring to. Is there a way to define the style of an element when it is first specified, and then its final state? I would like to be able to fully define a single-ste ...

Discovering the type of device and the most recent login location using PHP in Wordpress

I have created a function that displays the date of the last login for users, but now I want to also include the location and device from which the login was made. Despite searching, I haven't been able to find a solution to this issue. Can someone pr ...

Show the file download link once the file has been selected using jQuery's file upload feature

Is there a way to retrieve the local file path after choosing a file from the file upload? I want to add the file path to the href attribute of an anchor tag so that when I click on the link, it opens or displays the file. Can this be done using jQuery? ...

How do I retrieve the download URL for the file created using Python in my Heroku App?

After developing my Flask App, I uploaded several files to the Heroku filesystem. I'm aware that these files are removed every time the dyno restarts. Now, in my HTML/JavaScript frontend, I'd like to provide users with a download button for thes ...

Complete and submit both forms during a single event

Essentially, I have an event called onclick that takes form data and stores it in a variable. When another function is executed by the user, I want to send that variable through ajax within the function. This is the onclick event (first form): $('#n ...

There are two borders in place, with the second border present only on the right and bottom

Can someone help me achieve borders like the ones in this image? https://i.sstatic.net/qZHbK.png I tried using the after pseudo-element as shown below, but after learning from this discussion: Why can't an element with a z-index value cover its child ...

Using jQuery to create a complex hierarchy of div elements

I need assistance in creating this HTML structure using jQuery: <div id="container"> <div id="row0"> <div id="start0"></div> <div id="end0"></div> </div> <div id="row1"> & ...

Achieving vertical centering for content within :before/:after pseudo-elements

I'm striving to replicate a similar layout as shown in the image: Within a div element containing an image as part of a slideshow, I have utilized :before and :after pseudo-elements to create controls for navigating to the next (>>) or previous ...