2

I've been toiling, probably way too long, with a simple Child Theme for a version of Fukasawa.

I know that the @import method is deprecated. I also know that enqueuing it the preferred method. But...

I first tried The Codex, which seemed pretty darn simple to follow (although I've since read much that says "disregard codex"). I got as far as seeing that "Dashboard>>Appearance>>Themes" recognizes my child theme (fukasawa-child) for Preview/Activation.

But, when it comes to "Enqueuing", I fall short, and "no style at all" is a result. My site looks like a bare unordered list.

I think I'm overanalyzing, but I have more questions than I can find the answers to (which is why I think I'm overanalyzing):

/*
Theme Name: Fukasawa Child Theme
Theme URI: my_website_url/fukasawa-child/     /* Q1 - should this uri actually be 'my_website/wp-content/themes/fukasawa-child' - which is the true path of where it sits, or is there some unwritten rule that assumes 'wp-content/themes/' ??? */
Description: child theme for Fukasawa
Author: my name (veeps)
Author URI: my_uri.com                       /* /Q2 - can I do this, as the customizer?
Template: fukasawa                         //codex says to leave just like parent
Version: 1.05
*/

Q3 - Is the above (css opening information) referenced by my functions.php later?

NEXT:

function theme_enqueue_styles() {

    $parent_style = 'parent-style'; // Q4 - should 'parent-style' be replaced by 'fukasawa', or is that part of some pre-defined wp_universal_variable?

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css',  //should I eliminate the "...directory..." part of the get method?
        array( $parent_style )
    );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

if "get_template_directory_uri()" is referenced AND identical for both parent & child, and if I've been instructed (by codex) to leave them the same as original (i.e. file named style.css and 'fukasawa' as theme...probably to make life easier for newbies not unlike myself), then how does the php know where to look for parent vs. child?

1
  • How does the parent theme adds it stylesheets. File an edit with the relevant code used to add the stylesheets Commented Dec 14, 2015 at 7:17

1 Answer 1

1

Actually we deal with a single question per QA, but the basic of them can be clarified in a simple manner, we can proceed in this way:

First of all let me create a rudimentary child theme of Fukasawa for you.

I made a folder inside themes/ folder, named something. Inside the folder I made a style.css with the following content:

/**
 * Theme Name: whatever
 * Template: fukasawa
 */

And then I made another file inside the folder named functions.php and added the following content:

<?php
function theme_enqueue_styles() {
    wp_enqueue_style( 'kauwa-style', get_template_directory_uri() .'/style.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );

In my /wp-admin/themes.php now I've got a theme named "whatever", and activated it as a child theme of Fukasawa.

Answers:

A child theme works on the folder name of the parent theme, in this case it was fukasawa and that what we mentioned in template in stylesheet.

TESTING TESTING: Rename the folder from fukasawa to fuakasawa-kauwa and in your style.css do the same in template directive fukasawa-kauwa, you can see the your child theme still works. ;)

The style.css is the base of a child theme. We then added the functions.php to add the parent theme's stylesheet into our theme. Q4 - you can see I changed the handle's name to something odd. So you got your answer I guess. :)

I'm not answering Q1 and Q2 because both of them are not related to child theme things.

Enqueuing your theme's resources:

We don't require to load the child theme's stylesheet again, because it's already read by WordPress. Thanks to Pieter for pointing that out. But you need to be clear about one thing: as you are dealing with parent theme's features, so you have to mention that you are trying to load something from your child theme, not from the parent. And a way of doing this is to use the get_stylesheet_directory_uri(), it says WP to load things from the Child theme, not from its parent.

6
  • 1
    You know that the codex is a mess, and loading both the parent and child style loads the child styles twice. I have previously update thecodex with that info, but someone removes it everytime. Commented Dec 14, 2015 at 7:24
  • @PieterGoosen is right. We need not to enqueue the child theme's stylesheet again. I'm fixing the answer. Thanks a lot Pieter. Commented Dec 14, 2015 at 7:30
  • Thank you, Mayeenul and Pieter. I was/am indeed overanalyzing. The reason for Q1 and Q2 was to clarify whether or not functions.php was reading my child style.css and nullifying the rest accordingly. You've indirectly answered that, so thanks. Above, where you write, "clickaizo-style"...should I be referencing a specific path or file in its place (e.g. child theme directory, like "fukasawa-child)?
    – Veeps
    Commented Dec 14, 2015 at 7:45
  • @Veeps I already deleted that line, and rephrased things. Enqueue-hook can be anything, as you want. Commented Dec 14, 2015 at 8:08
  • @Veeps why on earth there is a space here: /* * it would be /** or simply /*. You better copy-paste my code for starting things. Folder name would better be hyphen-separated, like child-folder. :) Commented Dec 14, 2015 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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