Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Sometimes overwriting an existing function is not what you want to do. You'll will often find that a function has a lot of elements you already want and all you want to do is add some more to it. In those cases, you can use your child theme functions.php file to add the extra functionality to the existing function. There are some great examples of how you can add on to existing functions in twentytwelve and many of these examples you'll find in most WordPress themes. If you go to the functions.php file for twentytwelve and you go to line 64, you'll find register_nav_menu.
This is where you register the main menu inside your WordPress site. If you look at the site, you see there is a nav menu right here at the top and if I go into the Dashboard > Menus, you'll see that menu is listed right here. Your theme supports one menu and it's called Primary menu. Going back into functions.php, you'll see this is where Primary menu is defined. In your child theme you can now add additional menus, simply by duplicating this line in your child theme and wrapping it in a function so that it gets called.
That way you can add several different menus to your site by simply adding onto the existing function. The same goes for the sidebar. If you go to line 195, you find this function, twentytwelve_widgets_init, and this function creates a sidebar. So here you see there're three sidebars being called. In your child theme you're allowed to make your own widget init function, and in that function you can register more sidebars. These sidebars will then be appended to the existing ones so now you can have more sidebars then you had previously.
What's important to note about these functions, both register_nav menu and register_sidebar, is that they're wrapped in additional functions. You'll see here register_sidebar is wrapped in this existing function, twentytwelve_widgets_init, and if go up to register_nav menu on line 64, you'll see that register_nav menu is actually contained within a function called twentytwelve_setup. In your child theme you can create a new function and run that function, and within that function you would then puts register_nav menu or register_sidebar or other things.
The other cool thing about this is there's no limit to how many you can add. You can have 100 menus or 200 sidebar areas if you wanted to, although that would be hard to manage. But the reality is there is no limit here. You just hook in and then you add on whatever you need. There is one important thing to keep in mind, though. Remember how I said that functions.php from your child theme gets called before functions.php from your parent theme. That means you can't create a new function called twentytwelve_setup. If you do that, it'll crash everything, because there's no conditional statement here.
If you want to make a new function, you need to call something else, like my theme_setup and then you can call a new menu inside it. You also not create a new menu called primary menu, because there is already one created with that name. And you have to remember that your menu calls first. So if you create a new menu called Primary, that's the one that will kick in, and it'll ignore the one that's in here. Building child themes is all about doing more with less. Adding to a function instead of overriding it or overwriting it is a simple way of adding functionality with minimal effort.
Get unlimited access to all courses for just $25/month.Become a member
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.