[wordpress] Tạo Child Theme
In this article I will guide you how to edit wordpress theme by creating a child theme .
What is Child Theme
As you already know to get a nice interface, finding is important theme, but have not found a pleasant theme of our, sometimes we need to edit the pleasant. And if you are not careful your edits will be lost when you update the theme. So child theme help us avoid such incidents.
Child Theme is actually a theme so we build but inherited from a certain theme available that we want to correct. After you create a child theme, any child theme settings will be inherited its priority theme, ie attributes it to install the original theme will be disabled but what it does not have a new child theme is used.
The steps to create a child theme
Step 1: Go to the directory wp-content/themes create a folder named nametheme-child which “nametheme” the original name of the theme folder you want to edit. For example, I'm using the theme folder myknowledgebase then create a folder is myknowledgebase-child
Step 2: Create file style.css in the newly created directory with the following contents:
/* Theme Name: myknowledgebase Child Theme URI: https://cachhoc.net/myknowledgebase-child/ Description: myknowledgebase Child Theme Author: nguyenvanquan7826 Author URI: https://cachhoc.net Template: myknowledgebase Version: 1.0.0 Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready Text Domain: myknowledgebase-child */
In which you can change the parameters as you but the line Template The main theme is the name of the root directory, here's the original template in your theme is myknowledgebase
Step 3: Create file functions.php with the following content
<?php add_action( 'wp_enqueue_scripts', 'enqueue_parent_theme_style' ); function enqueue_parent_theme_style() { wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' ); } ?>
executable file will inherit everything from theme to theme your other newly created.
That's it, now in your theme settings only.
From now on, whenever edit css or function that you write in style.css or function.php you just created and all your edits will not be lost when the update theme.
Also you can edit the file's other original theme by creating the file with the same name as the original file of the theme. For example, you want to edit the page displaying posts, it is located in the file single.php Original theme of your time to create your theme folder 1 file is named single.php and write at your disposal.
Recent Comments