1

So I want to create a child theme for the premium theme Newspaper 7. I have read several tutorials and I have read through several answers on here, but I still do not understand the process of importing stylesheets into a child theme.

Newspaper 7 has three stylesheets: style.css editor-style.css style-woocommerce.css

I need to add all three of these to my child theme, but based on the wordpress codex example I have no idea on how to do this. Please help me edit the example below to fit my needs. I know how to use css, but these functions confuse me.

Wordpress codex example:

    <?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.

    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')
    );
}
?>

Edit: So this is the code I'm using now and it isn't working. I need to import the editor-style.css or my site breaks. Please help me figure out what I'm doing wrong.

    <?php
function my_theme_enqueue_styles() {

    $parent_style = 'parent-style'; // This is 'newspaper-style' for the Twenty Fifteen theme.

    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'editor-style', get_stylesheet_directory_uri() . '/editor-style.css' );
    wp_enqueue_style( 'style-woocommerce', get_stylesheet_directory_uri() . '/style-woocommerce.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' );
?>

Edit: I found the code I needed. I found out that the theme creator made a child theme demo and I found my answer in there.

1 Answer 1

0

All you need to do is import the stylesheet from your child theme. If the header is correct in your stylesheet, wordpress will understand that your theme inherits from the parent theme and will import that automatically.

3
  • Thanks for your reply but it is only half working. I need to also import editor-style.css but I'm not sure on how to add that to the code above. Mar 28, 2017 at 17:54
  • Why can't you use the same wp_enqueue_style() call, changing only the name of the stylesheet?
    – scott
    Mar 28, 2017 at 20:03
  • I don't know why it wasn't working but I found out that the theme creator made a child theme demo and I used the codes I found in there to import the stylesheets and it works now. Mar 28, 2017 at 20:06

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.