I am writing a theme on wordpress. I connected third-party libraries, everything is fine, but my style file does not work ....

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <link rel="stylesheet" href="style/mystyle.css"> <link rel="stylesheet" href="style.css"> <!-- Данное подключение тоже не срабатывает <link rel="stylesheet" href="http://mysite.com/style/mystyle.css"> <link rel="stylesheet" href="http://mysite.com/style.css"> --> <!-- И это тоже подключение тоже не срабатывает <link rel="stylesheet" href="./style/mystyle.css"> <link rel="stylesheet" href="./style.css"> --> <?php wp_head(); ?> </head> <body> <h1 class="red">RED</h1> 

mystyle.css:

 .red { color: red; } 

footer.php:

  <!-- FOOTER --> <h1>FOOTER</h1> <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"> </script> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"> </script> <?php wp_footer(); ?> </body> </html> 

Adding wp_head () and wp_footer () also did not solve the problem ....

The default wordpress project was created, the wp_my_themes folder was created in the themes (wordpressproject.com/www/wp-content/themes).

wp_my_themes folder contents:

  style (в этой папке лежит файл mystyle.css) 404.php (файл пуст) footer.php (содержимое написано выше) functions.php (файл пуст) header.php (содержимое написано выше) index.php (содержимое написано выше) page.php (файл пуст) screenshot.png (картинка темы) style.css (файл пуст, в комментах данные для описания темы) 
  • one
    if you are sure that there is a file mystyle.css in the style folder, then when connecting, specify the full path to the file (base url) may help - Arsen
  • one
    Try href="./style/style.css" - user242433
  • one
    open the console in the browser if it is not connected, then the file path is not correct and there will be a 404 error for this file, look at how the absolute link to the file is formed there, and understand what is wrong. - Raz Galstyan
  • one
    You do not need to write the full path, then this is not the right decision (but even if the path is correct but not 404 not found ), you don’t write the negative path correctly, and there is no one who can give a specific answer, since the hierarchy of your site is not knows not who. just see how they give file paths when connecting, ( htmlbook.ru/samhtml/ssylki/absolyutnye-i-otnositelnye-ssylki ) - Raz Galstyan
  • one
    <link rel="stylesheet" href="style/mystyle.css"> like that is <link rel="stylesheet" href="style/mystyle.css"> wrong. The relative link is relative to the requested page. - SeVlad

4 answers 4

Try it like this if the style file is in the theme folder you created

  <link rel="stylesheet" href="<?php echo esc_url( get_template_directory_uri() ); ?>/css/fonts.css"/> 
  • Your answer helped me to finally solve this problem! - Alexander

I am writing a theme on wordpress. I connected third-party libraries, everything is fine, but my style file does not work ....

The wp_head and wp_footer functions should be included in the subject . It will relieve from many problems, and not just with connection of styles.

But if suddenly there is a steady desire not to use the above-mentioned functions, then you need to connect manually with wp_enqueue_style .
// Additive . all other styles (not style.css) must be connected via this function, regardless of the presence of wp_head() and wp_footer() //

See How to properly connect a style file in your WordPress theme? with answers and comments.

  • Adding wp_head () and wp_footer () did not solve the problem .... With your link "How to connect the style file correctly in your WordPress theme?" I also read it carefully, a very good answer, but .... unfortunately ... this did not solve my problem with connecting the file with the styles .... - Alexander
  • one
    If we are talking about style.css, it can not solve. Others are connected by the specified function. I hope so. what is written in a question (heder) everything is cleaned? It is incorrectly written. Even the path to the style files is wrong. - SeVlad
  • one
    Here is another question from which the previous one was born. See the comments in the chat, I gave an example of a minimal topic. Everything connects if done correctly. - SeVlad
  • I also connected wp_head () and wp_footer () - Alexander
  • one
    I updated the answer. Other styles (and scripts) are connected via the functions wp_enqueue_style. (Wp_enqueue_script respectively) - SeVlad

In the console, writes that the file was not found? Try

  • one
    <link rel = "stylesheet" href = "../ style / mystyle.css"> - Yaroslav Palamarchuk
  • writes 404 in the console when the full path is written, and if not the full path, then everything is fine in the console, and in sources 404 writes .... "../" - also tried - Alexander
  • one
    Try the absolute path <link rel = "stylesheet" href = "/../ style / mystyle.css"> - Jaroslav Palamarchuk

The connection for this particular case looks like this:

 <link rel="stylesheet" href="<?php echo esc_url( get_template_directory_uri() ); ?>/style/mystyle.css"/> <link rel="stylesheet" href="<?php echo esc_url( get_template_directory_uri() ); ?>/style.css"/>