Answer the question
In order to leave comments, you need to log in
How to include CSS?
Hello. Using XAMPP, I'm building a test WordPress site. Before that, I used styles like this:
<link rel="stylesheet" type="text/css" href="<?php echo bloginfo('template_url'); ?>/css/index.css">
function add_resources(){
wp_enqueue_style('index', bloginfo('template_url') . '/css/index.css');
}
add_action('wp_enqueue_scripts','add_resources');
<body>
and a doctype. There is nothing else there. And a stylesheet that changes the background. The first way works great, the second doesn't. What to do?
Answer the question
In order to leave comments, you need to log in
Make sure before the closing </head> tag you have:<?php wp_head(); ?>
There is such a thing called "standards". So.
1. Styles must be at the root of the theme folder in the style.css file
2. This file must contain correct headers that define the theme (WP parses them)
3. The header.php template must contain the line wp_head();
4. Styles are connected via functions.php
function my_scripts_and_styles() {
// Theme stylesheet.
wp_enqueue_style( 'my-style', get_stylesheet_uri() );
// Theme script.
wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), NULL, true );
// Аргумент array( 'jquery' ) позволяет вызвать его как зависимость, вместо того чтобы вручную подключать.
// Если jQuery не нужен, передавайте пустой массив - array()
}
add_action( 'wp_enqueue_scripts', 'my_scripts_and_styles' );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question