
How to add Child Theme Support in WordPress Theme
- February 1, 2016
- Leave a comment
WordPress Theme is actually a collection of files that creates a layout for website content. In order to enhance the functionality of a Parent Theme, WordPress has already provided a feature to build Child Theme. This article is dependent on your knowledge of theme development, since it includes the method to add support in WordPress Theme in order to add content using Child Theme.
Let’s say you want to add a slogan in header of your website. You either have to re-locate header.php file in child theme or change parent theme’s header file (although this is not a recommended approach because it will be lost once you update the parent theme). If your parent theme provides proper support, you can do that by just writing a function and attach it using WordPress hooks.
To add slogan in header, we won’t recommend you to write a complete header.php file. Let’s assume that you already have a header.php file in your theme. At the end of this file, just add the following single call of WordPress action:
1 |
<div class="header-ad"><?php do_action('pt_after_header'); ?></div> |
Now using the child theme, go to functions.php file and put the following code to show the slogan in header of your website:
1 2 3 4 |
<?php function pt_show_header_slogan(){ echo '<h2>Best Website Development Services Provider Company</h2>'; }?> |
After that, you have to write action call to attach this function to hook called in header.php that is:
1 |
add_action('pt_after_header', 'pt_show_header_slogan'); |
You can repeat the same procedure to add more content in your header. For more details about the use of “add_action” or “do_action“, read the documentation on WordPress Codex.
User Comments