6

I've looked up the codex, some tutorials and they talk about adding custom css, but I couldn't find where do I add the style.css?

I did this, and still it won't have any effect.

/**
 * Proper way to enqueue scripts and styles
 */
function theme_name_scripts() {
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );

}

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

Of course it works if I do this:

<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>">

But of course its not the proper way of doing it.

  • I did 'wp_enqueue_scripts' in functions.php – Vegan Sv May 25 '15 at 1:38
  • does your theme have the wp_head() function? – Milo May 25 '15 at 3:39
  • No, it doesn't because it's such a theme that it only supposed to have index.php without header and footer and I thought you add wp_head only if you want to use a header.php. I will try adding it. – Vegan Sv May 25 '15 at 15:13
  • @Milo and Candid, thank you guys! It was wp_head. I should've read the notes, but they are not that clear anyway. – Vegan Sv May 25 '15 at 15:33
7

Make sure you have the files named and labeled correctly and in the right place.


functions.php located @ mytheme/functions.php

<?php
/**
 * Theme Functions
 */
function theme_name_scripts() {
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );
    wp_enqueue_style( 'style-name', get_stylesheet_uri() );

}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

style.css located @ mytheme/style.css

/*
Theme Name: Twenty Thirteen
Theme URI: http://wordpress.org/themes/twentythirteen
Author: the WordPress team
Author URI: http://wordpress.org/
Description: The 2013 theme for WordPress takes us back to the blog, featuring a full range of post formats, each displayed beautifully in their own unique way. Design details abound, starting with a vibrant color scheme and matching header images, beautiful typography and icons, and a flexible layout that looks great on any device, big or small.
Version: 1.0
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: black, brown, orange, tan, white, yellow, light, one-column, two-columns, right-sidebar, flexible-width, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, translation-ready
Text Domain: twentythirteen

This theme, like WordPress, is licensed under the GPL.
Use it to make something cool, have fun, and share what you've learned with others.
*/

If you are creating this theme yourself it's most likely spelled something wrong or you forgot something.

Make sure your template is getting the header if you are using a header.php:

<?php get_header(); ?> 

In your header or in the template you need to have:

<?php wp_head(); ?>

I'm guessing it's one of the above since you said it works when you add the tag. If not though try changing the name of the css file and/or adding a later priority. If you have plugins installed one of them might be using the same "handle" for their plugins stylesheet.

So instead of:

    wp_enqueue_style( 'style-name', get_stylesheet_uri() );

Try something random like:

    wp_enqueue_style( 'style189304', get_stylesheet_uri() );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.