I'm relatively new to creating a theme with WordPress, and I've been adding all the stylesheets (main and for each page) with the old echo get_stylesheet_uri();
. But I find out that this isn't the recommended way to do, and instead, to add all the styles within functions.php.
Old method (working):
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>">
New method (not working):
<?php
add_theme_support('post-thumbnails'); //Posts thumbnails
//Custom excerpt
function get_excerpt($excerpt, $length, $more_char = '...'){
return mb_strimwidth($excerpt, 0, $length, $more_char);
}
function theme_styles() {
//METHOD 1
//wp_register_style( 'main-style', get_template_directory_uri() . '/style.css');
//wp_enqueue_style( 'main-style');
//METHOD 2
wp_enqueue_style( 'main-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_styles' );
?>
I tried both methods above and none worked. Is there anything wrong besides my bad English?
Edit (SOLVED)
Thanks to Nathan Johnson who found the error. I wasn't using wp_head()
on my header.php
, therefore, WordPress wasn't finding where to put the enqueue style. Rookie error.
wp_enqueue_style( 'main-style', get_stylesheet_uri() );
wp_head()
?