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.
- Create a file called functions.php in your theme folder.
- Add functions to it.
The file automatically gets included into the theme, you don't have to do anything.
18 Responses to “Wordpress tips and tricks – functions.php” Leave a reply ›
I've used functions.php a few times before: what a damn good idea in the first place!
Great! Thanks for sharing this. I will try it.
I am looking at using that file to create some custom functions to override/mimic standard wordpress function. Should make additions a lot easier.
great advice, thanks!
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.
Nice hint Ben!
functions.php is indeed a very easy way to include anything in a wp-theme...
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.
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.
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.
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
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 ?
hi i am new to this site.i am a 20 yrs and working as a php trainee.i want the tips to improve my knowledge
thx for sharing..good job
Hi,
Your blog design is truly wonderful and very novel. The first thing I noticed about it was the fact that the page scrolls down but the Adsense in the sidebar remains in place. What a great implementation! I would really it if you cold share this trick with me...
Hi Ben,
Your post makes this all sound so easy, but I'm stuck on step #1. Where do I find the theme folder?
My site is still hosted at wordpress.com and doesn't have its own domain name yet. Is that why I don't see anything called theme folder? I have no idea where to find/create the functions.php thing.
Your help is appreciated.
Thanks!
Hi JoAnna - Unfortunately if you use WordPress.com then the changes mentioned in this tutorial are simply not possible. You would need to buy your own webspace and download and install WordPress yourself for to be able to make the changes I mentioned.