Change a Wordpress Theme (Child themes) | Adrenalina

Change a WordPress Theme (Child themes)

Publicado Por | 17 mayo , 2013 | Blog Adrenalina En, Technical SEO | No Comments

WordPress Theme Change - Child Theme

When we want to adapt a WordPress theme, if we don’t do the changes correctly then we run into the risk of wanting to updated the theme one day and be unable because we lose the edits. Example: if we edit style.css of our theme when we update it this will be “mashed” in the updated losing changes and returning to the original style.

Child themes

To update the theme without losing the edits you must use the Child themes, which will allow us to customize without having to edit it and not lose the changes made when we update.

To create child theme first thing is an installed main theme. Like Twenty Eleven.

We create a folder in our themes and we’ll include a style.css.

We gotta add the following header to ID it as child theme:

/*
Theme Name:     Child Theme Twenty Eleven
Description:    Child theme for Twenty Eleven edits
Author:         Adrenalina
Author URI:     http: //adrenalina.es/
Template:       twentyeleven
Version:        0.1
*/

The must-have lines are those of the theme name and the template folder, which points the theme we’re inheriting from and which we gotta write with the same name that the father folder: without caps or blanks.

Oue site will use the style.css of our Child theme, so we should add the following to the file:

@import url("../twentyeleven/style.css");

This line lets us import the style sheet of Twenty Eleven, so any new inputted line of code will be “added” to the imported one. This line of code must be placed after the header and before any css code or it won’t work.

Don’t forget to activate the Child theme in the dashboard.

Templates

Despite that we can carry out most edits in css and in functions.php, there are times when we’ll need to edit the template to gain a good result. But we mustn’t edit the theme’s template and we must make use of the Child Theme.

It’s important to know that any child theme file with the same name as one of the parent theme’s ones will replace it. Thus, to customize out theme we gotta copy the file we want to edit in the folder of the child theme and we’ll able to edit at will without fearing future theme updates.

To create a new template add this to the start of the file:

<?php
/*
Template Name: New Template
*/
?>

This will tell WordPress that this a page template and will be selectable when editing a page. We’ll be able to input our code.

Functions.php

The Child theme files with the same name replace parent theme ones. But functions.php is an excepction, since it’ll be separately loaded into the parent theme. You needn’t copy the functions.php of Twenty Eleven in the functions of the Child theme.

Developers can use the traits of the functions.php in the Child Theme which is loaded before the parent theme to input changes in functions and apapt them.

if ( ! function_exists( 'theme_special_nav' ) ) {
function theme_special_nav() {
//  Do something.
}
}

I hope I encourage youd to help custom your themes without fear to later updates.

Autor: mauro flores

Estudiamos y analizamos su negocio en profundidad, definimos objetivos y planteamos la estrategia de marketing más adecuada centrándonos en conseguir cada uno de los objetivos propuestos. Solicita Presupuesto Ahora

Uso de cookies

En este sitio web utilizamos cookies propias y de terceros para mejorar nuestros servicios, para que usted tenga la mejor experiencia de usuario y analizar su visita. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.