jump to navigation

Try Firefox - it's faster, and more secure than internet explorer. It even has a cute little mascot.

Journal

Wordpress tips and tricks - functions.php

May 31, 2007 | Web Design

Functions.php is a little known wordpress template file. Not many themes take advantage of it but , used properly, it can be incredibly powerful. The file can be used as a way to add your own functions to wordpress themes (hence the name).

One of the common misconceptions, at least based upon my experience with a past wordpress tips and tricks post, is that editing functions.php involves changing core wordpress files - meaning there will be issues when you upgrade wordpress.

I am against changing core files in wordpress. This makes upgrading a nightmare.

What functions.php does is let you create functions you can reuse in the theme. It works like a plugin file, being loaded when the theme is first loaded. You can then use the functions inside for anything you choose. For example in my first tips and tricks post I suggested using it to separate trackbacks and comments. You can also use functions.php as to implement theme control panel pages as seen in Regulus (pretty much the first theme to have a control panel).

And how do you make use of functions.php? It couldn’t be simpler.

  1. Create a file called functions.php in your theme folder.
  2. Add functions to it.

The file automatically gets included into the theme, you don’t have to do anything.

Comments »

  1. 1. Luke
    June 1, 2007

    I’ve used functions.php a few times before: what a damn good idea in the first place!

  2. 2. Blend
    June 3, 2007

    Great! Thanks for sharing this. I will try it.

  3. 3. Natron
    June 13, 2007

    I am looking at using that file to create some custom functions to override/mimic standard wordpress function. Should make additions a lot easier.

  4. 4. Iwo
    June 18, 2007

    great advice, thanks!

  5. 5. milo
    July 6, 2007

    functions.php is pretty slick, I’ve added a recent comments as well as a related posts function, but now I’m stuck with a dropdown tree menu function.

  6. 6. Daniel
    July 6, 2007

    Nice hint Ben!
    functions.php is indeed a very easy way to include anything in a wp-theme…

  7. 7. KVilla
    July 12, 2007

    Hello, I have been using your Regulus theme since creating my blog (on wordpress.com) because I really love it for its simplicity and straightforwardness, b/g color selection, tabs and the ability to change the header. However, I seem to be limited by the fact that there is no plugins function or am I missing something? (I would like to be able to insert video or a java poll please.) *Help!*

    Thanks in advance.

  8. 8. Ben
    July 12, 2007

    Blend, Iwo, Daniel - thanks :)

    Luke - it’s a great idea. Without this I wouldn’t have been able to do the admin page in Regulus. It opens up stacks of possibilities.

    KVilla - I don’t have any control over the features allowed on Wordpress.com. You would do better to ask them for help. The issue is largely a security one. They can’t allow people to do whatever they want as it would potentially open up security issues. If you really want to customise things they you should pay for some webspace and set up your own, self hosted, blog. Then you will be able to do whatever you like.

  9. 9. KVilla
    July 12, 2007

    Thank you for the quick response, Ben. I am new to wordpress.com. Can you please confirm if the plugins option is only allowed on wordpress.org, therefore all blogs hosted on its free site disallow plugins? Is there another way at showing a video (either as .swf or .wmv) as a post? Currently, I have an animated gift posted in one of the tabs at the site, but I would very much love to be able to show the longer video file instead.

  10. 10. Ben
    August 13, 2007

    KVilla - you are correct that plugins don’t work on wordpress.com. The best way to run wordpress is self hosted with the download from wordpress.org but obviously you need webspace for that. I would suggest asking for help on the wordpress.com forums as I don’t have much experience with the system over there so can’t really suggest anything.

    Hope you get it all working

  11. 11. Pablo Soto
    March 9, 2008

    Im glad if i find a “trick” or tip to put extra fields in comments.php

    How made this, run a query ?
    what happened with the comments.php to make it work ?

  12. People who link to this post...

Leave a message tell me what you're thinking

Please feel free to comment - I like receiving them - however I would appreciate you using your real name. I am not here to improve your search engine ranking. Abusive/ Inappropriate posts and advertisements will be deleted.

Binary Moon