Richard J Green

WordPress Development – functions.php

As I travel down the road of WordPress theme development, I have discovered many things.

A problem that has been hurting me for the last week at least as I develop the new theme is errors I would occasionally receive, which would read Cannot modify header information – headers already sent. For me as a non-programmer, this didn’t really mean an awful lot, and trawling the WordPress support forum didn’t help me hugely as I didn’t understand some of the lingo being used.

I had a starting point, which was my functions.php file. This filename was referenced in the errors, with a line number however upon inspection of that line, I couldn’t see a fault, so I looked elsewhere.

This evening, I compared my functions.php file to that of the TwentyTen theme which ships with WordPress 3.1, and I noticed something interesting. My functions.php file used multiple PHP statements opened and closed as needed, however the TwentyTen functions.php file only had a single set of PHP tags, opening at the start of the file and closing at the end, with each of the functions contained within it.

When I looked back at my file, I saw that the line indicating the error was in fact a closing PHP tag.

This post is more to serve as reference for other newbies out there trying to develop your first WordPress theme. Make sure that your functions.php file is a single PHP statement from start to finish with no leading or trailing line breaks or spaces. For me, this problem caused PHP errors when trying to modify Widgets in the admin interface, configure Plugins, manage the Theme settings and also stopped RSS and XMLRPC from working, so it’s a pretty big issue.

Exit mobile version