In 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.
In https://codex.wordpress/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.
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' );