WordPress child themes instructions. How to Create a WordPress Child Theme. How to Make a WordPress Child Theme
Want to create a WordPress child theme? After meeting WordPress Basics There is a completely justified and understandable desire to change the template design of the site to suit your tastes and needs. Creating a child theme is where you should start creating websites. In this article I will tell you how to create a child theme in WordPress.
Why create a child theme?
Creating a child theme is The best way customize your chosen one WordPress template. A child theme has all the features and appearance of the parent theme. You can do anything necessary settings without affecting the main template in any way. You can also easily update the parent theme without worrying about losing your settings.
Requirements
In order to make any changes to the template, basic knowledge of CSS/HTML is required, and it would also be nice to know PHP. You will really need the skills to copy and paste pieces of code from other sources.
To begin with, I would advise you to practice on localhost. You can also move your existing site to local server and practice on it or use dummy content.
Beginning of work
Any good topic WordPress can become the parent theme. However, there is huge selection themes and some of them are quite complex for the first experiments in creating child themes, so I decided to take a standard theme as an example Twenty Thirteen, which is one of the default themes in WordPress.
Create your first child theme
To begin, in the installation folder, open /wp-content/themes/ and create new folder for the child theme. Call it whatever you want. For example, I'll call it wpbdemo.
Open Text Document like Notepad and paste this code there:
/* Theme Name: WPB Child Theme Theme URI: http://www.wpbeginner.com/ Author: WPBeginner Template: twentythirteen Version: 1.0.0 */ @import url("../twentythirteen/style.css");
Theme Name: WPB Child Theme Theme URI: http://www.wpbeginner.com/ Description: A Twenty Thirteen child theme Author URI: http://www.wpbeginner.com Template: twenty-thirteen Version: 1.0.0 |
Save this document in the newly created child theme folder and name it as style.css.
The lines of code here are self-explanatory. What you really need to pay attention to is the line Template: twenty-thirteen.
This tells WordPress that our theme is a child theme and the parent theme folder is named twentythirteen. Please note that the parent folder name is case sensitive, i.e. if you enter “Template: TwentyThirteen”, nothing will work.
The last line of code imports the parent theme's stylesheet into the child theme.
This minimum requirements to create a child theme. Now you can go to the menu Appearance" Themes, where you will see WPB as a child theme. Click the Activate button to start using it on your site.
Since you haven't changed anything in the child theme yet, the site will use all the functionality and appearance of the parent theme.
Setting up a child theme
Each theme directory contains a file with styles – style.css. most often it is the main style file, where there is CSS. However, for some themes, this file only contains information about the theme. In this case, as a rule, CSS files are in a separate directory.
Here you will need some knowledge and skills in working with .
Google Chrome and Firefox come with a built-in inspection tool that allows you to view the CSS of many elements on a web page.
If you want to see CSS navigation menu, then simply move the mouse cursor to the menu, right-click and select “View code”.
Once you do this, the browser window will be split into two parts. At the bottom of the screen you will see the HTML and CSS for the page.
When you hover your mouse over different HTML lines, the inspection tool at the top of the screen will highlight the corresponding element. As you can see from the screenshot, I chose navigation menu.
The chrome tool will also display the CSS rules related to the selected element on the right side.
You can try editing the CSS right here to immediately see how everything will look. Let's change the background color . navbar on #e8e5ce .
Background color The navigation bar has changed. If you like it, you can copy this CSS rule and paste the child theme file style.css.
Navbar ( background-color: #e8e5ce; )
Navbar ( |
Save your changes to the style.css file and preview the site.
Repeat the process for anything you want to change in the theme's style sheet.
Here full list styles that I created for the child theme. Don't be afraid to experiment - change it at your discretion.
/* Theme Name: WPB Child Theme Theme URI: http://www.wpbeginner.com Description: A Twenty Thirteen child theme Author: WPBeginner Author URI: http://www.wpbeginner.com Template: twentythirteen Version: 1.0.0 */ @import url("../twentythirteen/style.css"); .site-title ( padding: 30px 0 30px; ) .site-header .home-link ( min-height: 0px; ) .navbar ( background-color: #e8e5ce; ) .widget ( background-color: #e8e5ce; ) .site-footer ( background-color: #d8cdc1; ) .site-footer .sidebar-container ( background-color:#533F2A )
Theme Name: WPB Child Theme Theme URI: http://www.wpbeginner.com Description: A Twenty Thirteen child theme Author URI: http://www.wpbeginner.com Template: twenty-thirteen Version: 1.0.0 @ import url ("../twentythirteen/style.css" ) ; Site - title ( padding: 30px 0 30px; Site-header. home - link ( min - height : 0px ; Navbar ( background - color : #e8e5ce; Widget ( background - color : #e8e5ce; Site - footer ( background - color : #d8cdc1; Site - footer. sidebar - container ( background - color : #533F2A |
Each WordPress theme has a different layout. Let's take a look at the structure of the Twenty Thirteen theme. There is: header, navigation menu, content part, bottom widget area, second (side) widget area, footer.
Each of these sections is processed various files in the twentythirteen folder. These files are called templates.
As a rule, these files have the name of the section to which they belong. For example, the footer is served by the file footer.php, the header and navigation menu are served by the file header.php. Some sections, such as the content area, are served by several files - “content templates”.
So, you need to get started by selecting the theme file that you want to change; copy it to your child theme.
For example, let's say you want to remove the "Powered by WordPress" text from the footer area and insert copyright information there. To do this: copy the footer.php file to the child theme, open it in simple text editor, such as Notepad. Find the line you want to remove and replace it with whatever you want. It might look like this: