好的。我一直在尝试将 css 样式表链接到我的网页。我一直在挠头试图弄清楚我做错了什么。有什么想法吗?
函数.php
<?php
function roofers_wp_resources() {
wp_enqueue_style('normalize', get_stylesheet_uri());
wp_enqueue_style('style', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'roofers_wp_resources');
?>
标题.php
<!DOCTYPE html>
<html>
<head>
<title>R.J Roofers</title>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php wp_head(); ?>
</head>
<body>
front-page.php
<?php get_header(); ?>
<div class="main-container">
<header class="main-header">
<!-- <h1 class="logo-name"><li><a href="index.html">R.J Roofer</a></li></h1>
--> <h1 class="logo-name"><a href="index.html">R.J Roofer</a></h1>
<nav class="main-nav">
<li class="nav-item-1"><a href="#">home</a></li>
<li><a href="services.html">services</a></li>
<li><a href="#">gallery</a></li>
<li><a href="about.html">about us</a></li>
<li><a href="contact.html">contact</a></li>
</nav>
</header>
<div class="quote-box-1">
<div class="quote-box">
<p class="quote-box-title">HOME ROOFING BRISBANE NO.1 FOR ROOF RESTORATIONS AND ROOF REPLACE</p>
<button class="quote-btn-1">BOOK A FREE QUOTE</button>
</div>
</div>
More Code..
最佳答案
get_stylesheet_uri()
为您的 style.css 文件提供完整的 url,因此在您的情况下,只有当您想要排队 style.css 文件时才好。
对于第二个文件,您需要传递一个包含文件名的完整 url。
假设您的规范化文件名为 normalize.css:
function roofers_wp_resources(){
wp_enqueue_style('my-theme-style', get_stylesheet_uri());
wp_enqueue_style('normalize', get_template_directory_uri() . '/normalize.css');
}
add_action('wp_enqueue_scripts', 'roofers_wp_resources');
请注意,如果您处理子主题,则需要将 get_template_directory_uri()
更改为 get_stylesheet_directory_uri()
。
关于php - Wordpress:CSS 文件不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44728928/