Wednesday, May 23, 2018

Wordpress - Create a Child Theme


How to Create a Child Theme
1.       Create the child theme directory, which will be placed in wp-content/themes folder. The name of your child theme directory is appended with '-child'. You will also want to make sure that there are no spaces in your child theme directory name, which may result in errors.
2.       The next step is to create your child theme's stylesheet (style.css). The stylesheet must begin with the following
/*
Theme Name: Twenty Fifteen Child Theme
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
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready Text Domain: twenty-fifteen-child
*/
                Note – Template “twentyfifteen” should be same as parent folder name. this is case sensitive. Otherwise you will get the error “the parent theme is missing. please install the x parent theme”
3.       Create a functions.php in your child theme directory. The first line of your child theme's functions.php will be an opening PHP tag (), after which you can enqueue your parent and child theme stylesheets.

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

where parent-style In your child code, replace the instance of 'parent-style' with 'twentyfifteen-style', like so:
parent_style = 'twentyfifteen-style';

No comments: