0

I didn't set up a child theme to start off with, so now I'm trying to do that. I do have the child theme active.

I read over this POST and still cannot get my child theme style.css to hook before anything else. I'm not well versed with coding and not sure how to write the functions.php for my child theme

My parent theme is using 3 stylesheets; style.css, custom.css and green.css (the latter is to have green be a dominant color for buttons, etc). When I make changes in my child themes style.css usually they won't take affect. Due to some caching issue within the database (I presume) an old custom.css seems to be taking precedent. Long story, but due to a web host account upgrade migration gone wrong.

I renamed the custom.css in the parent theme so it wouldn't be used, but that doesn't seem to matter. I even cleared everything out of it, still no joy. How would I write the functions.php to have my child theme work properly with CSS changes I make to it. Here's what I have now:

function child_scripts_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css', array() );
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri().'/style.css', array('mystile-style'), 'Mystile_Child' );
}
add_action( 'wp_enqueue_scripts', 'child_scripts_styles' );

Thanks in advance for any assistance!

EDIT:

I have tried the code above, yet my page div is loading first before scripts. I really don't understand how I should set the enqueue up or what should go in there.

Here is my site: Prints of Italy

  • Viewing the source of your page, your goal should be to have your child theme css come AFTER the parent theme css, if you wish to override the parent's styles. Your dependencies appear to reference the parent "Mystile". Is the source of the page reflecting this order? – jdm2112 Jan 23 '15 at 18:17
  • Forgive my ignorance here, it shows my child theme style.css just below the meta http-equiv line. Then down a bit on the page is: parent/green.css, then functions/shortcodes.css and last parent/custom.css – Charly Jan 23 '15 at 18:36
  • Sorry it's the parent/layout.css and then the parent/style.css which comes after my child style.css – Charly Jan 23 '15 at 18:42
  • It is a little hard to follow, please try to include all relevant code to the question. Also if you have worked out a solution by yourself it's better to add it as an answer than edit the question. :) – Rarst Jan 23 '15 at 22:36
  • My apologies, I not well versed with all of this. I edited my OP and gave a link to my site. Perhaps viewing the page source can explain better. – Charly Jan 24 '15 at 12:04
1

I was just setting up a parent theme recently and needed to create a snippet for other theme authors to use. These two in combination will load the correct style.css files, and in the correct order (child being loaded after parent).

In your parent theme's functions.php file:

function wpse_175802_scripts() {
    // Load our main stylesheet.
    wp_enqueue_style( 'wpse-175802-style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'wpse_175802_scripts' );

In your child theme's functions.php file:

function wpse_175802_child_theme_scripts() {
    wp_enqueue_style( 'parent-theme-css', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'wpse_175802_child_theme_scripts' );

If you wanted the custom.css files loaded, keep them in the child_theme_scripts function, following the same format as you used for the parent's style.css file.

Credit to the Codex and http://kovshenin.com/2014/child-themes-import/ for the original snippets.

  • What does wpse_175802_scripts stand for? Perhaps I'm not using the correct wording in my function? – Charly Jan 24 '15 at 12:06
  • @Charly wpse_175802 is an abbreviation for WordPress Stack Exchange Question #175802, which is what this is :) In the context of the code, wpse_175802_scripts is the name of the function. Adding hooks in WordPress follows the format of add_action( 'hook_name', 'function_name', priority, number_of_arguments );. For most actions, you don't need priority (default is 10) or number of arguments, but for many filters you do. When you change priority, it changes when the function executes - lower is earlier. – Jonathan Wondrusch Jan 24 '15 at 18:20

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.