wordpress: modifying themes

Editing Template Files

In a minute we'll learn how to determine which files to edit, but before we can do that, you'll need access to them. To edit a theme's files, you've got two choices:

  1. Use the Dashboard's built-in editor (Appearance | Editor)
  2. Edit template files in a programmer's text editor and upload them via FTP

Using the Built-In Editor

The first method is the easiest, but is much less powerful. Since you'll be editing in a standard web form, you won't have the advantage of a proper editor, such as syntax highlighting, line numbering, tag completion, or any of the dozens of other crucial features found in modern programmer's editors.

Once in the theme editor, select one of the template files on the right, then look for an "Update" button below the text area. If you don't see an Update button and see this sentence instead:

You need to make this file writable before you can save your changes.

it means your template files are not editable by the process the web server runs as. To fix this, you'll need to log in via FTP or ssh and change the file permissions. The Codex has a full page of instructions on this.

Permissions
In order to use the web-based theme editor, the theme folder will need to be writable by the web server. In this scenario, the server is running as user and group "nobody" and we're making the files writable by the group. We then click "Apply to enclosed" or similar so the change propagates to all files in that folder.

Editing via S/FTP

A much better solution is to log into your web host via S/FTP. You can either drag files to the desktop for editing in your favorite programmer's editor (we like TextMate) and then re-upload them, or configure your S/FTP client to edit files directly on the server. With this technique, the act of saving the document updates the file directly on the remote server. This is by far the easiest and most powerful way to work on WordPress themes, and we strongly recommend it.

Transmitprefs
Configuring preferences in the Transmit S/FTP client to launch double-clicked files in the TextMate editor. The Cyberduck client has a similar preference pane, as do many other S/FTP clients.

From here on, we'll assume you're editing files directly on the server via S/FTP configured to work with a good plain text editor (not a word processor).

Test Environments and Safety Nets

Since you'll be editing files live, you want to minimize the risk of making mistakes on a production web site. We recommend one or more of these techniques:

  • Create a "dev" or "staging" subdomain at your web host to work on. This way you can fiddle to your heart's content without worrying about breaking things on the public/live site.
  • Install a web server, MySQL database server, and PHP on your personal development machine.

For small nips and tucks where you have a high degree of confidence, it's generally OK to make live edits on a production site, but it's still a good idea to create a backup copy of the file you're about to edit before you touch it. If something goes really wrong, you can always re-install the last known working version of that file. In Transmit or Cyberduck, simply select the file you're about to edit and hit Cmd-D to create a backup copy in place.