Adrian
Adrian

Reputation: 3062

How to get child theme url in WordPress?

I am creating a child theme in WordPress. I have uploaded the assets folder that contains css and javascripts. It will be a custom theme.

Inside the tag i have included the the css file to get the css file.

There is a problem in my current code below:

<link href="<?php echo get_stylesheet_directory_uri(); ?>/assets/css/icons/icomoon/styles.css" rel="stylesheet" type="text/css">

The code below will work if it is without the styles.css after icomoon folder.

<link href="<?php echo get_stylesheet_directory_uri(); ?>/assets/css/icons/icomoon" rel="stylesheet" type="text/css">

I want the it to output as: //child_theme_url/assets/css/icons/icomoon/styles.css

I want the styles.css at the end of the include file.

Please help.

Upvotes: 7

Views: 18810

Answers (4)

Samyappa
Samyappa

Reputation: 531

Using this hook function in your child theme function.php

add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
function theme_enqueue_styles() {
    wp_enqueue_style( 'style', get_template_directory_uri() . '/assets/css/icons/icomoon/styles.css' );

}

Note: get_template_directory_uri() instead of get_stylesheet_directory_uri()

Upvotes: 4

Sagar Prajapati
Sagar Prajapati

Reputation: 90

Use following code for child theme directory.

<?php bloginfo('stylesheet_directory'); ?>

Upvotes: 1

user3173022
user3173022

Reputation: 57

Well,

to put at the end theme-child/style.css, you write the function (in functions.php):

function sp_enqueue_stylesheets() {
    wp_register_style( 'style-sp', get_stylesheet_directory_uri() . '/style.css', array(), '1.0', 'all' );
    wp_enqueue_style( 'style-sp' );
}
add_action('wp_enqueue_scripts', 'sp_enqueue_stylesheets', 9999 );

Thi is the lastest CSS in the header ;-)

Upvotes: 1

Jan Boddez
Jan Boddez

Reputation: 176

get_stylesheet_directory_uri() will return the child theme directory url, you got that bit just right. (get_template_directory_uri() would return the parent theme directory url.)

Also, if you want styles.css outputted, the first line of code will do that. Can't see what could be wrong with it. That means something else is likely not working as intended. Are you sure it shouldn't be style.css, for example? Anyway, such an issue would have nothing to do with WordPress correctly returning the child theme url or not.

Upvotes: 8

Related Questions