簡體   English   中英

有沒有辦法覆蓋 Wordpress 的 style.css 文件,以便我可以在主題模板上使用自定義 CSS?

[英]Is there a way to override Wordpress' style.css file so that I can use custom CSS on a theme template?

我正在嘗試將自定義 CSS 添加到呈現交互式待辦事項列表的主題模板中(我還使用一些 Javascript 使其工作)。 文件名為“dashboard.php”,我嘗試在其中鏈接自定義 CSS 文件,但我似乎無法覆蓋 styles.css(我認為這是 Wordpress 的默認設置)。

這是我在 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 ();

?>

如果我在 HTML header 中包含<link rel="stylesheet" type="text/css" href="/to-do-styles.css"> ,難道不應該覆蓋默認值 styles.css 嗎?

旁注,當我從to-do-styles.css復制內容並將其放入模板文件 (dashboard.php) 時,它工作正常; 但是,為了使模板文件簡潔,我想有一個單獨的文件。

簡而言之,我必須覆蓋默認的style.css文件,還是有辦法將它鏈接到模板?

以下是我的函數中的代碼。php,在我的主題文件夾中。

add_action('wp_enqueue_scripts', 'to_do_list_style');

function to_do_list_style() {

    wp_enqueue_style('/to-do-styles.css', get_stylesheet_uri());

}

請使用<head>而不是<header>來包含腳本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM