To create a child theme for a WordPress theme, follow these steps:
- Create a new folder in your WordPress theme directory and name it something like "child-theme."
- Inside the child theme folder, create a new file called "style.css." This will be the main stylesheet for your child theme.
- In the style.css file, add the following code at the top:
/* Theme Name: Child Theme Description: A child theme of [parent theme name] Template: [parent theme name] */
Replace "Child Theme" with the name of your child theme, and replace "[parent theme name]" with the name of the parent theme you are creating a child theme for.
- Add any custom styles to the style.css file that you want to override in the parent theme.
- Create a new file in the child theme folder called "functions.php." This file will allow you to add custom functions and hooks to your child theme.
- In the functions.php file, add the following code at the top:
<?php add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' ); function enqueue_parent_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' ); } // Add any other custom functions or hooks below this line ?>
This code will load the parent theme's stylesheet and make it available to your child theme.
- Activate your child theme by going to the WordPress dashboard and navigating to Appearance > Themes. Your child theme should now be listed as an available theme to activate.
- Customize your child theme by adding custom styles, functions, and hooks as needed. Be sure to test your changes carefully to ensure that they do not conflict with the parent theme or cause any issues with your site.
Using a Child Theme with your current WordPress Theme allows you to make changes in your Child Theme's functions.php and style.css which will NOT be overwritten when you update your theme.