tel: +2348055401551 (sms, whatsapp)
skype: tokunboajewole

Wordpress Tutorial: Create and use a functions.php file inside a child theme

Quoting Wordpress Codex:

Unlike style.css, the functions.php of a child theme does not override its counterpart from the parent. Instead, it is loaded in addition to the parent’s functions.php. (Specifically, it is loaded right before the parent’s file.)

In that way, the functions.php of a child theme provides a smart, trouble-free method of modifying the functionality of a parent theme. Say that you want to add a PHP function to your theme. The fastest way would be to open its functions.php file and put the function there. But that’s not smart: The next time your theme is updated, your function will disappear. But there is an alternative way which is the smart way: you can create a child theme, add a functions.php file in it, and add your function to that file. The function will do the exact same job from there too, with the advantage that it will not be affected by future updates of the parent theme. Do not copy the full content of functions.php of the parent theme into functions.php in the child theme.

The structure of functions.php is simple: An opening PHP tag at the top, and below it, your bits of PHP. In it you can put as many or as few functions as you wish. The example below shows an elementary functions.php file that does one simple thing: Adds a favicon link to the head element of HTML pages.


Note the highlighted block above: create a new functions.php file and add your functions in it.


1) Create a functions.php file inside child-theme folder 'twentyten-child', and add the following code:

<?php // my custom functions.php

// adding a favicon

function blog_favicon() {

echo '<link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'/favicon.ico" />';


add_action('wp_head', 'blog_favicon');


Note: other functions will be added between the opening and closing PHP tags.

2) Create a favicon using any online generator, paste a copy of the icon inside the wordpress root directory and the child-theme directory.

sample screenshot:


Add comment

Security code

I use Linux 24x7

Recent Comments