tema child wordpress
  • Home
  • /
  • Blog
  • /
  • Siti Web
  • /
  • Anche i Temi hanno una famiglia. Tema Child: cos’è e come si crea

Child Theme: What Is It and How To Create It

When the graphic style of the website you are creating using WordPress needs to be refreshed and customised, it is necessary to install a new free theme available in the WordPress library, or maybe a theme requiring a fee too.
This kind of theme is called “parent theme”.
If there is a parent well, it goes without saying... a child comes too!
The “child theme” is really very important. Let’s see through it then, finding out how it works and what its purpose is.

Content Index

  • What Is a Child Theme?
  • What is Its Purpose?
  • How To Install a Child Theme
  • How To Create a Child Theme Manually
  • How To Create a Child Theme Using a Plugin

What Is a Child Theme?

I like defining a child theme as some sort of “mask”, overlapping to the parent theme and getting all its properties and functions.
All the new changes that may occur are not overwriting the parent theme files.

So, the question is: why create two similar themes with the same properties and functions? Let’s find it out below.

What Is Its Purpose?

Themes are nothing but a group of files that get updated every time a change on a website is made. However, it may often happen that theme developers themselves release updates, and this can be seen every time that in the WordPress backend an update notification pops up right next to the theme installed.
It is a good and right thing to update a template. It is a method to keep it safer from potential external attacks, or simply to introduce new functions.
What happens then if a theme gets updated without having installed a child theme beforehand?
Well… not something you want to wish someone actually… but there is a real risk of losing every customisation made, may they be graphic or made by php functions.
And then it would be time to start the whole work all over again!!!

If a child theme is already installed instead, this can be updated without any trouble. It is good, however, to have a backup available before every update action. Your customisations remain unaffected. New updates overlap the parent theme files only.
Child themes are so important!

How To Install a Child Theme

After describing how paramount this theme can be, now the issue turns to how it is possible to install it.
There are two possible options to install a child theme:

  • Manually (ideal solution for newbies)
  • Using a plugin (a good solution both for newbies and developers willing to save time while working)

How To Create a Child Theme Manually

Ready to get down to work to create a child theme on your own? Follow the steps below… Don’t worry, it is much easier than you think!
A previous installation of a theme on WordPress is necessary though. Default WordPress themes, such as Twenty Nineteen are totally ok. Ready? Let’s go then!

  1. Access to your website files via FTP or via File Manager
  2. Open the Wp-Content folder and then the folder called Theme
  3. Now create a new folder and rename it after this pattern: themename-child. If the Twenty Nineteen theme is installed, your folder bears the name twentyninenteen-child
  4. Create a text file using Notepad and then turn the file extension from .txt into .css
  5. Open the file and paste the following code: /*
    Theme Name: Twenty Nineteen Child
    Theme URL: http://example.com/
    Description: Child Theme for Twenty Nineteen Theme
    Author: Your Name
    Author URL: http://example.com/about/
    Template: twentynineteen
    Version: 0.1.0
    */
  6. Modify every line after the theme you are using
  7. Upload this file in the folder previously created, available following this path: wp-content/themes/yourtheme-child. The theme you are creating receives the name you want and, in the Template field, the parent theme name is added, allowing the child theme to take its characteristics
  8. Now the function.php file can be created. Open a text file and paste the code below, without changing anything of it: <?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’ );
    }
  9. Upload this file too in your child theme path (wp-content/themes/yourchildtheme)
  10. Eventually open your WordPress dashboard and activate the child theme you created, that can be found following this path: Layout>Themes, along with all the other WordPress themes available

Your theme has now been installed completely… manually! Quite easy, wasn’t it?!

How To Create a Child Theme Using a Plugin

As shown above the manual procedure is rather simple and it only takes a few minutes to be completed. If you do not like to get down to work on specific website files directly or if you are a developer ready to put your efforts for a few seconds (and not minutes) only, then the best solution for you is to install a child theme using a plugin.
There are several plugins allowing you to activate a child theme on your website in just a few clicks. One of the most reliable and most frequently used themes is the one called Child Theme Generator. Let’s take a look at how it works.
First of all, this plugin needs to be installed: go to Plugin > Add New and search for the plugin wanted. Click on Install and then on Activate.

After its activation, search for it among the plugins installed and click on Create.

Then a window pops up, where the plugin settings are displayed.

The plugin activated selects the active parent theme automatically. This is the only important field you need to be sure to check. If you need to activate a child theme for another parent theme you can choose it from the drop-down menu.

The Title, Description, Child Theme Url fields are further information to be added, undoubtedly useful to define all details, but just optional. You can choose either to fill them or to leave them blank.
The Author, Author Url, Version and Include GPL License fields are already filled instead, and so just to be left without any changes.
Click now on the Create a Child Theme option.
The creation of your child theme has now been completed and ready to be activated from the theme panel.
See? Just a couple of clicks and that’s all!

Conclusion

If before reading this column you had no idea about how important child themes could be, and totally had no clue about how to create them… Well, now you know!
Quite easy, wasn't it?

Now you are ready to install a child theme everytime you want!

Valeria



Anche i Temi hanno una famiglia.
Tema Child: cos’è e come si crea

Quando si vuole personalizzare lo stile grafico del sito WordPress che si sta sviluppando è norma installare un nuovo tema presente nella libreria di WordPress oppure uno a pagamento. Solitamente questo tema viene denominato tema “genitore” o tema “parent”.

E se esiste un genitore significa che esiste anche un figlio!

Il tema “figlio” o tema “child” è di fondamentale importanza. Vediamo quindi insieme che cos’è e a cosa serve.

 
 

Che cos’è un Tema child

Mi piace definire il tema child come una sorta di “maschera” che si sovrappone al tema genitore e che eredita tutte le sue caratteristiche e tutte le sue funzionalità.
In questo modo tutte le nuove modifiche non andranno a sovrascrivere i file del tema “parent”.

A questo punto potresti chiederti: perché creare due temi uguali con le stesse caratteristiche e le stesse funzioni? Te lo spiego subito.

 

A cosa serve un Tema child

I temi non sono altro che un insieme di file che si aggiornano ogni volta che si apportano delle modifiche al nostro sito. Spesso, però, può succedere che siano gli stessi sviluppatori del tema a rilasciare aggiornamenti. In pratica ce ne accorgiamo ogni volta che dal backend di WordPress vediamo una notifica di aggiornamento in corrispondenza del tema installato.

E’ cosa sana e giusta aggiornare il proprio template. Si tratta infatti di un modo per renderlo più sicuro da eventuali attacchi esterni, o semplicemente per introdurre nuove funzionalità.

Ma cosa succede quindi se aggiorniamo un tema senza installare prima un tema child?

Beh…di certo non lo auguro a nessuno, ma c’è il rischio che si perdano tutte le personalizzazioni apportate (grafiche oppure tramite funzioni php).

Quindi sarai costretto a rifare tutto da capo!!!

Se hai un tema child installato, invece, potrai aggiornare tranquillamente il tuo tema (è buona norma avere sempre a disposizione un backup prima di ogni aggiornamento) e le tue personalizzazioni non verranno minimamente toccate. I nuovi aggiornamenti, infatti, andranno a sovrascrivere solamente i file del tema “parent”.

Il tema child è perciò importantissimo!

 

Come si installa un tema child

Dopo che abbiamo finalmente compreso l’importanza di questo tema ora sicuramente ti starai chiedendo come si installa. 

Bene, per installare un tema child è possibile seguire due metodi:

  • un metodo manuale, ma che non richiede particolari doti di programmazione;
  • un metodo tramite plugin, una soluzione adatta sia per i principianti, sia per gli sviluppatori che vogliono risparmiare tempo durante lo svolgimento del loro lavoro.
 

Creazione del tema child tramite il metodo manuale

Se vuoi cimentarti nella creazione manuale di un tema child, seguimi ad ogni passaggio.

Tranquillo non è complicato!

Ovviamente prima di procedere dovrai aver installato su WordPress un tema. Va benissimo anche uno dei temi di default di WordPress, come Twenty Nineteen. Una volta fatto questo…cominciamo!

1 Innanzitutto accedi ai file del tuo sito via FTP oppure tramite File Manager.

2 Apri la cartella wp-content e successivamente la cartella theme.

3 Procedi ora con la creazione di una nuova cartella e rinominala seguendo questo schema: nometema-child. Quindi se hai installato il tema Twenty Ninenteen la tua cartella si chiamerà twentyninenteen-child.

4 Con un semplice Blocco Note crea un file di testo e modifica l’estensione del file da .txt a .css.

5 Apri il file e incolla al suo interno questo codice:

/*

Theme Name: Twenty Nineteen Child

Theme URI: http://example.com/

Description: Tema Child per il tema Twenty Nineteen

Author: Inserisci il tuo nome

Author URI: http://example.com/about/

Template: twentynineteen

Version: 0.1.0

*/

6 Modifica ogni riga adattandola al tema che stai utilizzando

7 Carica questo file nella cartella creata in precedenza che si trova a questo percorso: wp-content/themes/tuotema-child.

In questo modo avrai assegnato un nome al tema che stai creando e, nel campo Template, avrai inserito il nome del tema genitore, cioè quello da cui il tema child erediterà le caratteristiche.

8 Procedi ora con la creazione del file function.php. Apri quindi un semplice file di testo e incolla il codice qui sotto così com’è senza apportare alcuna modifica.

<?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’ );

}

9 Carica anche questo file nel percorso del tuo tema child (wp-content/themes/tuotema-child)

10 Ora non ti resta che aprire la tua Bacheca di WordPress e attivare il tema child creato che troverai in Aspetto > Temi insieme a tutti gli altri temi di WordPress.


Il tuo tema figlio installato con il metodo manuale è pronto! Facile, no?!

 

Creazione del tema child tramite plugin

Come vedi la procedura manuale è piuttosto semplice e comporta qualche minuto di tempo. Se, però, non ti piace mettere mano ai file del sito oppure se sei un programmatore che su alcune cose preferisce perderci pochi secondi invece di qualche minuto, allora il metodo ideale per te per l’installazione del tema child è sicuramente quello tramite plugin.

Esistono infatti diversi plugin che ti permettono di attivare un tema child sul tuo sito in pochissimi click. Quello che mi è capitato di usare più spesso e con cui mi trovo molto bene è il plugin Child Theme Generator. Vediamolo insieme.

Innanzitutto installa il plugin: vai su Plugin > Aggiungi Nuovo e cerca il plugin in questione.  Clicca poi su installa e successivamente su attiva.

Child Theme Generator

Dopo averlo attivato cercalo tra i plugin installati e clicca su Crea.

Plugin Child Theme Generator

Ora ti si aprirà una schermata in cui vedrai le impostazioni del plugin.

Impotazioni Plugin Child Theme Generator

Come potrai vedere il plugin seleziona di default il tema genitore attivo. Questo è l’unico campo importante che dovrai controllare. Nel caso in cui tu volessi attivare un tema child per un altro tema “parent” potrai selezionarlo dalla tendina relativa.

I campi Intestazione, Descrizione, Url del tema figlio sono informazioni aggiuntive e sicuramente molto utili per definirne tutti i dettagli, ma sono facoltative e quindi sei liberissimo di compilarli o di lasciarli vuoti. I campi Autore, Url dell’Autore, Versione e Includere licenza GPL solitamente sono pre-compilati e puoi lasciarli impostati così come sono.

Fatto questo clicca sul pulsante Crea un tema figlio.

Bene, il tuo tema child è creato. Ora basta attivarlo dal pannello dei temi.

Tema child Plugin Child Theme Generator

Visto?? Sono bastati due semplici click!

Conclusione

Se prima di leggere questo articolo non sapevi perché fossero così tanto importanti i temi child, ma soprattutto non avevi la minima idea di come crearli…be’ ora lo sai!
Semplice vero?

Ora sei pronto per installare un tema child ogni volta che vorrai!

 

Valeria

Child Theme: What Is It and How To Create It

When the graphic style of the website you are creating using WordPress needs to be refreshed and customised, it is necessary to install a new free theme available in the WordPress library, or maybe a theme requiring a fee too.
This kind of theme is called “parent theme”.
If there is a parent well, it goes without saying... a child comes too!
The “child theme” is really very important. Let’s see through it then, finding out how it works and what its purpose is.

Content Index

  • What Is a Child Theme?
  • What is Its Purpose?
  • How To Install a Child Theme
  • How To Create a Child Theme Manually
  • How To Create a Child Theme Using a Plugin

What Is a Child Theme?

I like defining a child theme as some sort of “mask”, overlapping to the parent theme and getting all its properties and functions.
All the new changes that may occur are not overwriting the parent theme files.

So, the question is: why create two similar themes with the same properties and functions? Let’s find it out below.

What Is Its Purpose?

Themes are nothing but a group of files that get updated every time a change on a website is made. However, it may often happen that theme developers themselves release updates, and this can be seen every time that in the WordPress backend an update notification pops up right next to the theme installed.
It is a good and right thing to update a template. It is a method to keep it safer from potential external attacks, or simply to introduce new functions.
What happens then if a theme gets updated without having installed a child theme beforehand?
Well… not something you want to wish someone actually… but there is a real risk of losing every customisation made, may they be graphic or made by php functions.
And then it would be time to start the whole work all over again!!!

If a child theme is already installed instead, this can be updated without any trouble. It is good, however, to have a backup available before every update action. Your customisations remain unaffected. New updates overlap the parent theme files only.
Child themes are so important!

How To Install a Child Theme

After describing how paramount this theme can be, now the issue turns to how it is possible to install it.
There are two possible options to install a child theme:

  • Manually (ideal solution for newbies)
  • Using a plugin (a good solution both for newbies and developers willing to save time while working)

How To Create a Child Theme Manually

Ready to get down to work to create a child theme on your own? Follow the steps below… Don’t worry, it is much easier than you think!
A previous installation of a theme on WordPress is necessary though. Default WordPress themes, such as Twenty Nineteen are totally ok. Ready? Let’s go then!

  1. Access to your website files via FTP or via File Manager
  2. Open the Wp-Content folder and then the folder called Theme
  3. Now create a new folder and rename it after this pattern: themename-child. If the Twenty Nineteen theme is installed, your folder bears the name twentyninenteen-child
  4. Create a text file using Notepad and then turn the file extension from .txt into .css
  5. Open the file and paste the following code: /*
    Theme Name: Twenty Nineteen Child
    Theme URL: http://example.com/
    Description: Child Theme for Twenty Nineteen Theme
    Author: Your Name
    Author URL: http://example.com/about/
    Template: twentynineteen
    Version: 0.1.0
    */
  6. Modify every line after the theme you are using
  7. Upload this file in the folder previously created, available following this path: wp-content/themes/yourtheme-child. The theme you are creating receives the name you want and, in the Template field, the parent theme name is added, allowing the child theme to take its characteristics
  8. Now the function.php file can be created. Open a text file and paste the code below, without changing anything of it: <?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’ );
    }
  9. Upload this file too in your child theme path (wp-content/themes/yourchildtheme)
  10. Eventually open your WordPress dashboard and activate the child theme you created, that can be found following this path: Layout>Themes, along with all the other WordPress themes available

Your theme has now been installed completely… manually! Quite easy, wasn’t it?!

How To Create a Child Theme Using a Plugin

As shown above the manual procedure is rather simple and it only takes a few minutes to be completed. If you do not like to get down to work on specific website files directly or if you are a developer ready to put your efforts for a few seconds (and not minutes) only, then the best solution for you is to install a child theme using a plugin.
There are several plugins allowing you to activate a child theme on your website in just a few clicks. One of the most reliable and most frequently used themes is the one called Child Theme Generator. Let’s take a look at how it works.
First of all, this plugin needs to be installed: go to Plugin > Add New and search for the plugin wanted. Click on Install and then on Activate.

After its activation, search for it among the plugins installed and click on Create.

Then a window pops up, where the plugin settings are displayed.

The plugin activated selects the active parent theme automatically. This is the only important field you need to be sure to check. If you need to activate a child theme for another parent theme you can choose it from the drop-down menu.

The Title, Description, Child Theme Url fields are further information to be added, undoubtedly useful to define all details, but just optional. You can choose either to fill them or to leave them blank.
The Author, Author Url, Version and Include GPL License fields are already filled instead, and so just to be left without any changes.
Click now on the Create a Child Theme option.
The creation of your child theme has now been completed and ready to be activated from the theme panel.
See? Just a couple of clicks and that’s all!

Conclusion

If before reading this column you had no idea about how important child themes could be, and totally had no clue about how to create them… Well, now you know!
Quite easy, wasn't it?

Now you are ready to install a child theme everytime you want!

Valeria



Articoli Collegati

adobe xd

Adobe XD: Come realizzare interfacce di siti web… e non solo!

Leggi