WordPress development

Child themes or child themes in WordPress – Second Part – How to create a child theme.

We continue with this second part on WordPress child themes.

If you want to read the first part: https://www.mowomo.com/temas-hijos-wordpress-child-theme/

If you have read the first part, it is but that you are clear about what WordPress child themes are and what they are for

In this second part I am going to explain how to create a child theme or child theme in WordPress. It's very easy, you just have to be careful to know at all times which theme you are working on and never modify the parent theme.

I will give the example that you have downloaded a theme from repository of free WordPress themes  and you have chosen it as I explain in this post: Choosing a WordPress theme and you have also installed it in your WordPress and you already have it configured.

Now you want to modify the archive.php because it happened that the theme that we liked did not have a featured image in the archive.

What do we have to do?

This cannot be set from the administrator, unless the theme includes this option or from FTP within the archive.php over writing the code of the main theme, because if we do, we will not be able to update our theme or if we update, we will have to re-enter the code again.

  1. We will enter via FTP and create a folder in wp-content/themes/ that is called for example: themename-child or themename-child, in this way we identify the parent and child theme at a glance
  2. Inside this folder we create two files:
    • style.css
    • functions.php
  3. In the style.css file we will put the following:
    (themename is the original name of the theme we downloaded)
/*
 Theme Name:  nombredemitemapadre-hijo
 Theme URI: miweb.com
 Description: Tema hijo para nombredemitemapadre
 Author: mi nombre
 Template: nombredemitemapadre
 Version: 0.1
*/
  1. In the fuctions.php file we put the following:

(This code is placed at the top of the fuctions.php, if you need to add functionality, always below this code)

What we do is put the styles of the parent on top and “enqueue” the styles of the child, that is, we put them in the queue just below.

function mitemahijo_enqueue_styles() {
$nombredemitemapadre_style = 'nombredemitemapadre-style'; 
wp_enqueue_style( $nombredemitemapadre_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'nombredemitemapadre-hijo', get_stylesheet_directory_uri() . '/style.css', array( $nombredemitemapadre_style ), wp_get_theme()->get('Version') );
}
add_action( 'wp_enqueue_scripts', 'mitemahijo_enqueue_styles' );
  1. We copy the archive.php file from the parent with its hierarchy, that is, if it is inside a folder we will also copy the name of the folder and add the file inside
  2. We make the modifications inside this file (archive.php but in the child theme folder
  3. We activate the child theme leaving the parent theme always in the list of installed themes, but not activated. The one that is activated is only the child theme, but both have to coexist in the WordPress installation

Now we have an active child theme where we can make all the modifications we want and as many tests as we want and the good thing is that our modifications will last, even if we update the parent as many times as necessary.

If you need the development of a child theme (or WoredPress child theme) or a WordPress development from scratch exclusively for you or your client, do not hesitate to contact us, and we will give you the best solution or if you need other developments ask us for a quoteYou will be pleasantly surprised at our prices. 

¡Subscribe to our newsletter and receive our offers, news and discounts directly to your email!