1

On child themes: It is stated:

... create a file called style.css. This is the only file required to make a child theme.

Then, it states:

The correct method to import the parent themes stylesheet into the child theme is to use wp_enqueue_style() in your child theme's 'functions.php':

<?php
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
function enqueue_child_theme_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('parent-style')  );
}

So apparently I also need a functions.php in the child? At first, I thought this function was to go into the style.css, but that does not seem reasonable.

What happens if I do not include the functions.php - will the style.css create a child theme (looking just like it's parent at first)?

1

Yes you will need to enqueue parent theme styles into child theme. Adding style.css in child theme will not automatically add parent theme's styles too.

You can enqueue parent theme's styles like this. Create a new functions.php in child theme and paste this.

function enqueue_child_theme_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('parent-style')  );
}
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
  • Thank you. I thought so, but the "only" folder had thrown me off. – user62269 Oct 18 '14 at 3:15
  • @robert: what is PHP_INT_MAX also, what does array('parent-style') do? thanks. – Tara Jan 13 '15 at 3:47
0

You can , strictly speaking, create a child theme with just a stylesheet. To achieve this, you will need to import the parent stylesheet into the child stylesheet using the @import method.

This should however be avoided due to page load times for one. @import negatively impacts page load time. You should go and read this post on SO

The correct way is to create a functions file and then enqueueing the parent stylesheet as you correctly pointed out. I will later update the codex page with this info for the benefit of others as well.

Just on your last question, if you don't import/register the parent stylesheet in the child theme, your site will not have any styling, except for the styling that you have added in the child theme stylesheet

EDIT

I have updated the child theme codex page and removed the fact that you only need the stylesheet to make a child theme work

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.