style.css 在 wordpress 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21079255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
style.css not working in wordpress
提问by user3188096
I have a problem with Wordpress, I've created all needed files including style.css index.php and so on but the page is not styled. In header, among other things, I've put this
我的 Wordpress 有问题,我已经创建了所有需要的文件,包括 style.css index.php 等,但页面没有样式。在标题中,除其他外,我把这个
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="text/css" href="<?php bloginfo('template_url'); ?>/css/style.css" />
回答by Gil Sousa
Add stylesheet other than style.css
, open function.php
and add the following code.
添加除 之外的样式表style.css
,打开function.php
并添加以下代码。
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
function theme_name_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() . "/css/bootstrap.css" );
wp_enqueue_style( 'style-name', get_stylesheet_uri() . "/css/bootstrap-responsive.css" );
}
Add the style.css file using thins:
使用 Thins 添加 style.css 文件:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
回答by Madhuraman Ghimire
Add the following to your functions.php, it should work.
将以下内容添加到您的functions.php,它应该可以工作。
function EnqueueMyStyles() {
wp_enqueue_style('my-custom-style', get_template_directory_uri() . '/css/my-custom-style.css', false, '20150320');
wp_enqueue_style('my-google-fonts', '//fonts.googleapis.com/css?family=PT+Serif+Caption:400,400italic', false, '20150320');
wp_enqueue_style('my-main-style', get_stylesheet_uri(), false, '20150320');
}
}
add_action('wp_enqueue_scripts', 'EnqueueMyStyles');
回答by Super Model
Open function.php file and past the following code.
打开 function.php 文件并粘贴以下代码。
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
function theme_name_scripts() {
wp_enqueue_style( 'style-name1', get_stylesheet_uri() . "/css/style.css" );
wp_enqueue_style( 'style-name2', get_stylesheet_uri() . "/css/bootstrap.css" );
}
回答by Lino
In functions.phpadd this code it will link style.cssfile to your WordPress theme
在functions.php中添加此代码,它将style.css文件链接到您的WordPress主题
function load_scripts() {
wp_enqueue_style( 'stylecss', get_stylesheet_uri() );
}
add_action('wp_enqueue_scripts', 'load_scripts' );
回答by Chastic Fy
when you also have 2 site URLs or home URLs in your plugins or CSS when you look it up in the inspection on chrome or some browser. And opening this in a new tab (btw this should not be accessible)::
当您在 chrome 或某些浏览器的检查中查找时,您的插件或 CSS 中还有 2 个站点 URL 或主页 URL。并在新选项卡中打开它(顺便说一句,这不应该是可访问的)::
then try to put
然后尝试把
"/" without the "" in your localhost or whatever > phpmyadmin > database (of WordPress) > wp_options >> "siteurl" and "home" in option_value
“/”没有“”在您的本地主机或任何> phpmyadmin > 数据库(WordPress)> wp_options >> option_value 中的“siteurl”和“home”
回答by 5377037
Replace template_url
with template_directory
in bloginfo
and all done like:
替换template_url
为template_directory
inbloginfo
并全部完成,如下所示:
<link ... href="<?php bloginfo('template_directory'); ?>/css/bootstrap.css" />
<link ... href="<?php bloginfo('template_directory'); ?>/style.css" />
回答by Abder
I had the same problem, but I fixed it by looking carefully in my code. This is what I wrote before:
我有同样的问题,但我通过仔细查看我的代码来解决它。这是我之前写的:
<link href="<?php bloginfo('stylesheet_url'); ?> rel="stylesheet" type="text/css" media="all" />
As well as the following code helped me solved the problem:
以及以下代码帮助我解决了问题:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
Can you see the difference? Comment below if you have any questions.
你能看到差别吗?如果您有任何问题,请在下方评论。