Chamberlain Design logo

Chamberlain Design

A Romp Through functions.php

Sorry about the lack of post last week but it was my birthday and I was busy scoffing cake.  Now I’m feeling lazy so, as they say, ‘here’s one I made earlier':

Here are a few useful snippets of code based on the functions.php file of this website’s WordPress theme.  But first, an introduction to what functions.php is.

What is functions.php?

The functions file is an optional theme file that you can use to add universal tweaks and additions to your theme.  The WordPress Codex suggests that you use this file to do things like adding or enabling theme features, defining functions that are used in several different theme template files and setting up back-end options menus.

You can use this file for so many different things that defining what it is proves quite difficult.  It’s easier just to show you what I have used it for.  I’ve changed a few details to make these snippets more generally applicable.  So, here we go.

Adding a Custom Menu

This is how I added the custom header navigation menu.  Doing it like this enables you to more easily edit your menu in the dashboard.

Then, to add this menu to your theme, just add this code where you want it to go:

Enqueueing a Conditional Internet Explorer Stylesheet

If you want to add extra CSS stylesheets to your theme, you should enqueue them.  This is how you enqueue a conditional IE CSS file.

Adding a Custom Post Type

On this site, the portfolio items are a custom post type.  This is the minimum you need to add a custom post type but there are many more options.

I hope these snippets will help you technical people out there and I’m sorry if I’ve lost everyone else.  If you don’t know what you’re doing, don’t try this at home – pay someone like me to do it for you.

Due to a pointed lack of interest and through traffic to my main site, I’ve decided to start doing these every other week instead.  That is unless you leave begging comments below.

22nd June 2013

No comments yet - why don’t you get the ball rolling?

Join the Discussion

Your Name:

Your Email:


Comments using offensive language will be hurled into the abyss.