0

I am trying to get a child theme to work. At first it didn't load because it didn't recognise it as a child theme. Now it does work but when I activate it, it loads a version of my page seemingly without any css or something. There's only text and images there, but no styling. Is it that it isn't using the parent theme fully or something?

I am just starting with Wordpress so I'm sorry if I'm not very clear or using the right terminology. Thanks in advance.

This is my functions.php file:

<?php
function my_theme_enqueue_styles() {

$parent_style = ‘twenty seventeen-style’;

wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
    get_stylesheet_directory_uri() . '/style.css',
    array( $parent_style ),
    wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
?>
  • If this code was copy/pasted from what you are using, double check the quotes around the $parent_style value. In what you have they are "curly" quotes and may need to be retyped. ‘twenty seventeen-style’ vs. 'twenty seventeen-style' – butlerblog Aug 30 '17 at 19:59
  • I don't think the handle for an enqueued style can have a space in it. This might work better: twenty-seventeen-style – Jeff Mattson Aug 30 '17 at 20:10
0

You'll have to enter that code at the start of the functions.php file in your child theme to include the parent theme's style.css file

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );

}

visit this page for more information

  • I have used that page and copied exactly what they said to put in the functions.php file. I'll put what is in there in the original question. – Benjamin Aug 30 '17 at 18:46
  • perhaps it is the commas in that line $parent_style = ‘twenty seventeen-style’; replace it with $parent_style = 'twenty seventeen-style'; ..I've tested your code on a test child theme and it's working perfectly fine ( after replacing the commas with proper ones ) – 7asobate- Aug 30 '17 at 19:59
  • I tried, but it still didn't work – Benjamin Aug 31 '17 at 7:31
  • Okay, so I made a really dumb mistake, I made a typo while naming the functions.php file, so it didn't recognise it. Thank you for your help! – Benjamin Aug 31 '17 at 13:44
  • we've all been there :) .. glad it's solved – 7asobate- Aug 31 '17 at 18:41
0

Did you follow the instructions here: https://codex.wordpress.org/Child_Themes ?

I thought that all that was required is to put this as the header in the Child Theme's style.css (example per the above link)

/*
 Theme Name:   Twenty Fifteen Child
 Theme URI:    http://example.com/twenty-fifteen-child/
 Description:  Twenty Fifteen Child Theme
 Author:       John Doe
 Author URI:   http://example.com
 Template:     twentyfifteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags:         light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
 Text Domain:  twenty-fifteen-child
*/

Then you can add additional CSS below the above style.css header, and additional functions in the Child Theme's functions.php . And then put your own templates in the same folder.

That's the way I have always done my child themes. No wp_enqueue_style needed, etc.

  • I've followed that tutorial, copied their exact code (only changing the things specific for my theme). They use the wp_enqueue_style , so that's what I did – Benjamin Aug 31 '17 at 7:33

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.