style.css not working in wordpress

可紊 提交于 2019-12-10 11:56:54

问题


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

<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" />

回答1:


Add stylesheet other than style.css, open function.php and add the following code.

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:

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">



回答2:


Add the following to your functions.php, it should work.

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');



回答3:


Open function.php file and past the following code.

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" );
}



回答4:


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.




回答5:


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)::

then try to put

"/" without the "" in your localhost or whatever > phpmyadmin > database (of WordPress) > wp_options >> "siteurl" and "home" in option_value




回答6:


Replace template_url with template_directory in bloginfo and all done like:

<link ... href="<?php bloginfo('template_directory'); ?>/css/bootstrap.css" />
<link ... href="<?php bloginfo('template_directory'); ?>/style.css" />



回答7:


In functions.php add this code it will link style.css file to your WordPress theme

function load_scripts() {
    wp_enqueue_style( 'stylecss', get_stylesheet_uri() );  
}

add_action('wp_enqueue_scripts', 'load_scripts' );


来源:https://stackoverflow.com/questions/21079255/style-css-not-working-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!