0

In https://codex.wordpress.org/Child_Themes is written that the best practice for including style.css in the Child Theme one must put the code below into the functions.php of your Child Theme but replacing the 'parent-style' with the parametr of your Parent Theme which can be found in the functions.php of your Parent Theme. I couldn't find that in the file of my Theme, and there is not much of a code there. The method to include the Parent Theme stylesheet using @import is not working for me, the css that put in the file are not displaying themselves on the site in any browser.

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')
    );
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

And I have one working example of this enqueue but for a different theme:

/**
 * Enqueue the parent theme stylesheet.
 */

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

/**
 * Enqueue the child theme stylesheet.
 */

add_action( 'wp_enqueue_scripts', 'vantage_child_style', 20 );
function vantage_child_style() {
    wp_enqueue_style( 'child-theme', get_stylesheet_uri() );
}

The name of my Theme is Samsklad and I don't know how to implement the code within my Child Theme's functions.php, I'm no good with PHP.

  • How does your parent theme enqueue its stylesheet? Search for occurences of style.css in its files (presumably the functions.php). Can you post these in your question? – kero Nov 2 '18 at 13:45
  • I found it in the header.php - <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css" type="text/css" media="screen"/> – Evgeny Sudakov Nov 2 '18 at 14:00
  • Ok, this means your theme wasn't developed using the WordPress best practices and you should disregard those articles. Either overwrite the header.php and use the suggested code (the handle (parent-style, twentyfifteen-style, ...) does not matter then) – kero Nov 2 '18 at 14:52
  • You mean put the first code into functions.php as it is? – Evgeny Sudakov Nov 2 '18 at 15:09
1

You posted in a comment that the current theme uses the following code in its header.php

<link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/style.css" type="text/css" media="screen"/>

This is not WordPress best practice and hence the linked tutorials fail you.

How to go on from this?

Copy header.php from parent to child theme, remove the line containing style.css, then you can place the following code in your child theme's functions.php:

function my_theme_enqueue_styles() {
    wp_register_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' );

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.