我是wordpress的新手,我知道关于我的问题有很多答案,但是即使我已经尝试了很多,但不管我做什么,它仍然不起作用。
我已经制作了自己的自定义wordpress主题,并且可以使用引导外部链接样式进行工作,但是我自己的style.css不适用于该主题。只是要确保我已经将其包含在header.php中。我使用本教程converting-html-sites-to-wordpress-sites
这是我的header.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>walabi</title>
<!-- Font Awesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
<link href="https://fonts.googleapis.com/css?family=Niconne&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Nunito&display=swap" rel="stylesheet">
<!-- Custom CSS -->
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url');?>css/style.css">
<!-- Bootstrap core CSS -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<!-- Material Design Bootstrap -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.8.7/css/mdb.min.css" rel="stylesheet">
<!-- Cache Control -->
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<meta http-equiv="refresh" content="600">
</head>
<body>
<!-- Header Start -->
<nav id="paham-nav" class="navbar navbar-expand-lg fixed-top scrolling-navbar">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"><i class="fas fa-chevron-down" style="color: aliceblue"></i></span>
</button>
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav ml-auto nav-flex-icons">
<li class="nav-item">
<a class="nav-link" href="index.php">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="career.php">Career</a>
</li>
</ul>
</div>
</nav>
<!-- Header End -->
这是我的function.php(首先,这个function.php的工作原理是什么?当我什至没有声明的时候)
<?php
//Definir le répertoire du thème
define("THEME_DIR", get_template_directory_uri());
//Enlever le générateur de tags meta pour la sécurité (les gents ne peuvent pas voir quelle version WP)
remove_action('wp_head', 'wp_generator');
// ENQUEUE STYLES
function enqueue_styles() {
/* Main CSS */
wp_register_style( 'style', THEME_DIR . '/style.css', array(), '1', 'all');
wp_enqueue_style( 'style' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_styles' );
?>
这是我尝试的答案:
style-css-in-wordpress-doesnt-work-after-adding-header-php-file
style-css-not-loading-in-wordpress-theme
style-css-not-working-in-wordpress
只需确保这是我的目录:
在我的目录中有:
有人可以帮我解决这个问题吗?自昨天以来我仍然无法解决这个问题
答案 0 :(得分:2)
您尝试回显bloginfo('stylesheet_url')吗? 也许该函数不返回任何内容或错误的路径。
为了进行测试,您还可以将css文件的路径直接放在HTML上。
<!-- Custom CSS -->
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url');?>css/style.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="PATH_TO_CUSTOM_CSS/css/style.css">
答案 1 :(得分:1)
在functions.php上尝试
function enqueue_styles() {
/* Main CSS */
wp_register_style( 'style', THEME_DIR . '/style.css', array(), '1', 'all');
wp_register_style( 'bootstrap', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css');
wp_register_style( 'material', 'https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.8.7/css/mdb.min.css');
add_action( 'wp_enqueue_scripts', 'enqueue_styles' );
wp_enqueue_style( 'style' );
}
答案 2 :(得分:1)
您是否检查过源代码并查看页面上是否正在调用样式表?如果是这样,请尝试单击该链接或将其粘贴到另一个选项卡中,并确保已加载该链接;否则,请尝试将其尝试从中加载CSS的路径与实际路径进行比较。
您还可以右键单击该页面,然后单击检查,然后转到网络标签并重新加载该页面,它会告诉您该样式表是正在加载还是无法加载。
当您执行此操作时,请告诉我,我会再检查一下是否需要更多帮助。
答案 3 :(得分:1)
查看您所拥有的这一行:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url');?>css/style.css">
bloginfo('stylesheet_url')
已经是样式表本身的完整URL,包括文件路径和名称。因此,您无需在其后附加css/style.css
!只是使
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
注意:样式表应位于主题目录中,而不是在单独的“ css”目录中。