'Is there a way to override Wordpress' style.css file so that I can use custom CSS on a theme template?
I am trying to add custom CSS to a theme template that renders an interactive to do list (I am also using some Javascript to make it work). The file name is "dashboard.php," and within it I have tried linking a custom CSS file, but I can't seem to override styles.css (what I believe to be Wordpress' default).
This is the code I am using within dashboard.php:
<?php
/*
* Template Name: Dashboard
* Template Post Type: page
*/
get_header();
?>
<header>
<link rel="stylesheet" type="text/css" href="/to-do-styles.css">
</header>
<div id="myDIV" class="header">
<h2>My To Do List</h2>
<input type="text" id="myInput" placeholder="Title...">
<span onclick="newElement()" class="addBtn">Add</span>
</div>
<ul id="myUL">
<li>Hit the gym</li>
<li class="checked">Pay bills</li>
<li>Meet George</li>
<li>Buy eggs</li>
<li>Read a book</li>
<li>Organize office</li>
</ul>
<?php
get_footer ();
?>
If I include <link rel="stylesheet" type="text/css" href="/to-do-styles.css"> in the HTML header, shouldn't that override the default styles.css?
Side note, when I copy the content from to-do-styles.css and place it into the template file (dashboard.php), it works fine; however, to keep the template file concise, I would like to have a separate file.
In short, must I override the default style.css file, or is there a way to link it to the template?
The following is my code within my functions.php, within my theme folder.
add_action('wp_enqueue_scripts', 'to_do_list_style');
function to_do_list_style() {
wp_enqueue_style('/to-do-styles.css', get_stylesheet_uri());
}
Solution 1:[1]
please use <head> instead of <header> to include scripts.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Wom |
