How to Make Changes in Child Theme On Top of Parent Theme?

In fact, there are four means of changing a parent theme:

  1. Update the file style.css of the parent theme: create it in the child theme, import data of the parent theme and override style properties (you have described it).
  2. Update the file functions.php: create it in the child theme and add your functions, hooks. If the parent theme allows doing it, then override functions of the parent theme.
  3. Overload the .php file of the parent theme: copy the necessary file in the child theme and to change it as you wish (you have described it).
  4. Change the information output via WordPress filters. For example, you do not want to create a file in a child theme in order to remove a title page, for example, is_page(). So, you need to see how the title appears in the parent theme. If the theme author has foreseen this point, it is possible. If not, it isn’t. For example, in the subject heading is derived through a function of the theme_the_title threads(), and this function is defined in functions.php as follows:
if ( ! function_exists('theme_the_title') ) {
  function theme_the_title() {
  ?>
<h1><?php the_title() ?></h1>
<?php
 }
}

Verification of  function_exists ('theme_the_title') gives an opportunity to override the function. And you can remove a header by defining the same function in the child theme in functions.php file:

function theme_the_title() {
  if( is_page() ) return '';
  ?>
  <h1><?php the_title() ?></h1>
  <?php
}

So you will not have to copy the file of the parent theme in whole to remove the header on the  page is_page. But it is not always possible.

RELATED:  What is Child Theme in WordPress?

The author also may foresee the possibility to change part of the theme file by using filters. The author defines the filters in the theme, through which you can modify the layout without copying the file to a parent theme. For example, you need to remove the header for the types is_page(). The header is output in the parent theme as follows:

$title = '<h1>'. get_the_title() .'</h1>';
echo apply_filters('theme_the_title', $title);

We can filter out the header by defining a filter in functions.php of the child theme:

add_filter('theme_the_title', 'delete_title_on_single');
function delete_title_on_single(){ return ''; }

// We can briefly write as follows
add_filter('theme_the_title', '__return_empty_string');

Article last updated on November 22, 2020

Leave a Comment