Struggling with making Custom CSS take precedence over Bootstrap in a Wordpress Theme

I'm facing an issue with my custom CSS not being able to override bootstrap on this specific site.

Although I have experience using bootstrap on various platforms without any issues, I am currently working on a WordPress project for a client where nothing seems to work. No matter what I do, I am unable to apply background colors or other customizations to classes within divs as they simply won't display. Even using pre-existing bootstrap classes inside divs is ineffective. It's as if my CSS file is not being recognized at all. For instance:

.my-blue-background { 
    background-color: blue;
}

<div class = "container my-blue-background">
    ...
</div>

Or:

<div class = "my-blue-background">
    <div class = "container">
        ...
    </div>
</div>

And also:

<div class = "container text-center">
   <h1>Hello World!</h1>
</div>

Moreover:

<div class = "container">
    <h1 class = "text-center">Hello World!</h1>
</div>

I've tried using !important. I've even attempted copying CSS files and pages from other themes, which worked fine, but any attempt to modify their custom stylesheet does not reflect the changes. Deleting their custom stylesheets doesn't show any difference on my website either. I've cleared cache, tested on different browsers and devices, and confirmed that my enqueues are set up correctly by trying both methods:

wp_register_style('bootstrap', get_template_directory_uri() . '/inc/css/bootstrap.min.css', false, '4.0.0', null);
wp_enqueue_style('bootstrap');

wp_register_style('customstyle', get_template_directory_uri() . '/inc/css/custom.css', false, '0.0.1', null);
wp_enqueue_style('customstyle');

As well as:

wp_register_style('bootstrap', get_template_directory_uri() . '/inc/css/bootstrap.min.css', false, '4.0.0', null);
wp_register_style('customstyle', get_template_directory_uri() . '/inc/css/custom.css', false, '0.0.1', null);

I'm at a loss as to why this isn't working on my configured settings. Any insights or solutions would be greatly appreciated.

Answer №1

It appears that there are incorrect spaces in your HTML code

<div class = **the space here is wrong** "container text-center">

The accurate version should be:

<div class="container text-center">

Answer №2

To ensure that the custom style loads after the bootstrap style, follow these steps:

wp_register_style('bootstrap', get_template_directory_uri() . '/inc/css/bootstrap.min.css', false, '4.0.0', null);
wp_enqueue_style('bootstrap');

wp_register_style('customstyle', get_template_directory_uri() . '/inc/css/custom.css', array('bootstrap'), '0.0.1', null);
wp_enqueue_style('customstyle');

If this solution does not work, providing a link to the website would be beneficial.

Answer №3

After some investigating, I discovered that the issue stemmed from the cache within the WordPress server. This cache was causing a delay in loading my recent edits, creating the illusion that I was unable to override bootstrap's presets. To address this, I made adjustments to the CSS and Javascript enqueues like so:

wp_enqueue_style('customstyle', get_template_directory_uri() . '/inc/css/mystyle.css', array(), rand(111,9999), 'all' );
wp_enqueue_script('customjs', get_template_directory_uri() . '/inc/js/myscripts.js', array(), rand(111,9999), true);

By implementing these changes, the server was prompted to refresh the stylesheets and scripts, resulting in immediate updates on my end.

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

Implement a sliding effect for the navigation menu

I'm trying to figure out how to make this menu slide in when the hamburger menu is clicked. The background of the menu is an SVG, not just a shape. Does anyone have any suggestions or ideas on how I can achieve this effect? For reference, here is the ...

My HTML document is not displaying the JavaScript variable as expected

I have created a JavaScript function with several variables and attempted to test it to display the variables in my HTML document. However, I am facing an issue where the variables do not appear as expected. Specifically, I am trying to insert the variable ...

Height not being generated by Div element

I am encountering an issue with a div element that contains an h2 and three nested div elements. Despite not explicitly setting a height for the container div, it is not expanding to accommodate the varying heights of the inner divs. This problem is causin ...

The functionality of displaying one div while hiding another upon click seems to be malfunctioning

Can anyone lend a hand? I'm having trouble with my code - the section isn't showing up after clicking the button. <script> $("#img1").on('click', function() { $("#div1").fadeIn(); $("#div2,#div3,#div4").fadeOut(); }); $(" ...

What are the steps to include an image in the body of an email when sending it through SMTP?

I'm currently working on creating an email verification module and I want to include my company logo at the beginning of the message. However, all the solutions I've come across so far only explain how to attach an image to the email. What I aim ...

Is it possible to combine two conditions using CSS?

Hello, I have a question about CSS. In my navigation bar, I have 3 links with different styles: #p1 { font-family: Arial, Helvetica, sans-serif; font-size: 13px; line-height: 45px; font-weight: bolder; color: #999999; text-dec ...

Every time I try to access my website, all I see is the WordPress installation process page

After initially hosting a WordPress website, I made the decision to switch over to SPIP. However, when attempting to access the site on my laptop, it continues to bring up the WordPress installation process. Interestingly enough, the website appears to lo ...

What is the method to process a JSON path containing a special character like "@"?

I'm attempting to retrieve JSON data from an API with the following structure. My current approach involves using JavaScript. The code snippet I have utilized is displayed below. <p>"stations": [</p> <p id="data"></p> ...

Displaying an element outside with reduced opacity using fabric js and controls placed above overlay

The property controlsAboveOverlay in Fabric.js is a boolean that, when set to true, will display the controls (borders, corners, etc.) of an object above the overlay image. The overlay image is an image that can be placed on top of the canvas. Currently, ...

Off-center alignment in left margin with Bootstrap 3

When using bootstrap 3, I have noticed that the left margin starts to indent gradually with each row. Here is a screenshot demonstrating the issue: please see here The code for the first two rows in the image looks like this: <div class="row"> ...

Tips for ensuring all images are the same size within a div element

https://i.stack.imgur.com/EkmWq.jpg Is there a way to make sure all the images fit perfectly inside their respective border boxes without appearing stretched? I've tried setting fixed height and width within a div, but they always end up looking off. ...

Determine the character's position in an input field by tracking mouse movements

I am in need of a way to determine the position of a character in an input field based on mouse movement. For example, if the input field contains the value 'abcde' and I hover my mouse over the character 'a', the position should be ...

Adding an arrow to a Material UI popover similar to a Tooltip

Can an Arrow be added to the Popover similar to the one in the ToolTip? https://i.stack.imgur.com/syWfg.png https://i.stack.imgur.com/4vBpC.png Is it possible to include an Arrow in the design of the Popover? ...

``Is there a way to align content in the middle of the page while

Hey everyone, I need some help with centering the content on my webpage. The sidebar is always active and I want to make sure the main content is centered like the highlighted text. The issue is that it's currently centered based on the width of the e ...

The function is not recognized while executing .mb_YTPlayer();

I'm currently working on creating a webpage with a video background using jquery.mb.YTPlayer, but I'm encountering an issue. I'm seeing an error message that says "Uncaught TypeError: undefined is not a function". Here is the code I a ...

Combining data using D3's bar grouping feature

I'm currently exploring ways to group 2 bars together with some spacing between them using D3. Is there a method to achieve this within D3? I found inspiration from this example. var data = [4, 8, 15, 16, 23, 42]; var x = d3.scale.linear() .doma ...

When I try to call another page by clicking a button in my Django Framework application, the functionality does not seem to be functioning

I have included all the necessary code, JavaScript function, as well as the Django code. I am attempting to redirect to result.htm from index.html upon clicking the "RUN" button, but the code below is not achieving the desired result. index.html <o ...

Unable to view indicators and slides are not transitioning in Bootstrap carousel

I am in the process of developing a website with bootstrap, but I am encountering issues with the carousel feature. Despite copying the code directly from their official page, the carousel remains non-functional. The indicators are missing, and the slides ...

Jquery for controlling the navigation menu

I'm new to JavaScript and facing 3 challenges: 1. When I click on the parent <li>, the correct content of the child <sub> does not show up. Each category like "colors, shapes, sizes" should have corresponding child categories like "green, ...

When the form is submitted, use jQuery to smoothly transition the page to a specific

I have a form and a div called "success". When the form is submitted, the "success" div is displayed. I am attempting to make it so that when the form is submitted, the page slides to the "success" div. Here is the code I am using: $.ajax({ type: "P ...