3

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" />
2
  • What does your directory look like? How does the parsed HTML look? Commented Jan 12, 2014 at 19:38
  • Did you notice that you have two href attributes in that link (last line)? Commented Mar 14, 2018 at 15:59

8 Answers 8

5

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');
Sign up to request clarification or add additional context in comments.

1 Comment

Your answer is not scoped properly.
5

For my case, i had not linked CSS. So i solved it by doing the following:

  1. I created a file header.php this file had my html code and inside of this file, instead of manually including the css file using link , i called a php function wp_head(); which helps wordpress to take control of my head section.

    <!DOCTYPE html>
    <html>
      <head>
        <?php wp_head(); ?>
      </head>
      <body>
        <h1>Wordpress</h1>
      </body>
    </html>

After that i had to create another new file in the themes folder called functions.php and linked style.css in this file using the following code.

<?php
function files() {
  wp_enqueue_style( 'style', get_stylesheet_uri() );
} 
  add_action( 'wp_enqueue_scripts', 'files' );

?>

Comments

4

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

1 Comment

style-name inside wp_enqueue_style, must be unique. Use add_action( 'wp_enqueue_scripts', 'theme_name_scripts' ); function theme_name_scripts() { wp_enqueue_style( 'style-name1', get_stylesheet_uri() . "/css/bootstrap.css" ); wp_enqueue_style( 'style-name2', get_stylesheet_uri() . "/css/bootstrap-responsive.css" ); }
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" );
}

Comments

0

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.

Comments

0

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

1 Comment

I mean you can always try this. Easy to go back if it does not work. I did not read your problem. But this was the fix I was looking for and found the solution my self. just remember what was there in the first place.
0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.