Editing Files

跳转至: 导航搜索


There are times when you will need to edit the WordPress files, especially if you want to make changes in your WordPress Theme. WordPress features a built-in editor for editing files from within your browser whilst online: The Theme Editor. You can also edit files copied or stored on your computer and then upload them to your site using an FTP client.

Before editing any of your WordPress files, check the following:

BACKUP! And Work from Backups 
Work from copies of backup files when possible and/or make sure that you backup your information frequently as you work and make changes. Keep backups in a safe place.
File Permissions 
When working online, you need to set the appropriate file permissions to modify and save them. If you see a note at the bottom of the WordPress Built-in Editor panel that says "If this file was writable you could edit it.", this means you need to change the file permissions before you can make any changes.
Use a Text Editor to Edit Files 
To make changes to files outside of the built-in Plugin or Theme Editor, use a text editor. DO NOT USE A WORD PROCESSING PROGRAM. Word processors change the quote marks to characters and may convert other characters or bring in unwanted code; these changes will cause the file to break. There are also some HTML generator programs that should not be used for similar reasons.

Using the Theme Editor and Plugin Editor

WordPress contains two built-in editors that allows you to edit Theme files directly from within your browser. They are called the Theme Editor and Plugin Editor.

Access the Theme Editor from the Administration > Appearance > Editor menu.

The Plugin Editor is located at Administration > Plugins > Editor.

To view a file in these editors, click on the file from the right-hand side list.

More information on editing themes is available at Theme Development and Using Themes. You can learn more about editing plugins at Writing a Plugin and Plugin Resources.

Be aware that if the theme you edit is updated, your changes will be overwritten. To better organize your changes and protect them from updates, consider creating a Child Theme in which to keep all your changes.

What Files Can Be Edited?

From within the WordPress Built-in Editor, the following file types may be edited, if writable:

  • HTML
  • PHP
  • CSS
  • .htaccess
  • TXT (and related text-like files such as RTF)

Things You Need to Know

Instant Changes 
The changes you make to files using the WordPress editors are instant; the changes happen online, in real-time. You and any visitors to your will see the changes immediately.
Because of the immediate nature of the changes, it's usually safer to edit copies of your files offline, test, and upload your changes when they are verified.
Always make sure you have a current backup before editing files.
Editor Features 
The built-in WordPress Plugin and Theme editors are very basic, allowing easy access to view and edit plugin and theme files on your site only. There are no built-in editor features for search and replace, line numbers, syntax highlighting, code completion, or other advanced editing features.
Hint: Use your browsers internal search to help find code within the visual editors.
File Permissions 
To edit a file using the built-in WordPress Plugin or Theme Editors, the permissions for that file must be set to writable (at least 666). You can change the permissions on files by using a FTP client program, web-based file manager provided by your host, or from the command-line using SSH (secure shell). Your options depend on the type of access your host offers.
Make a Mistake? Use the Backup Files 
Backup all files before editing. If you make a mistake that causes errors, a site crash, a blank screen, or blocks access to your WordPress Dashboard, delete the changed file and replace it with a good one from your backup.
No backup? Download a fresh copy of the file you edited from the original source, replace it, and start over. BACKUP FIRST.
Security Warning 
By default, any user that logs in with administrative permissions can access the WordPress Plugin and Theme editors, and change any theme or plugin file on your site in real-time.
To combat accidents, errors, and even hacking, you may wish to disable the ability to edit files within the WordPress theme by adding the DISALLOW_FILE_EDIT function to your wp-config.php file.

Editing Files Offline

To edit files offline, you can use any of the recommended text editors to create and edit files and an FTP client to upload them. Make sure to view the results in your browser to check if the desired change has taken effect.

Note: It is not recommended to change core WordPress files other than wp-config.php. If you must change anything else, take notes and store them in a text file in your WordPress root directory and make a backup copy of them for future reference and upgrades.

Using Text Editors

Editors to Avoid

Note: If you use an external editor to create and edit files, such as a standard word-processor, it can corrupt the file you are editing.

Editors to avoid include:

  • Microsoft Word
  • WordPerfect
  • OpenOffice/LibreOffice
  • Apple iWork Pages
  • Microsoft Publisher
  • Microsoft Works
  • Microsoft Excel
  • Adobe Photoshop
  • Adobe Illustrator
  • Adobe Dreamweaver
  • Any do-it-yourself instant web page software.

To use Adobe Dreamweaver or Microsoft FrontPage, keep these guidelines in mind:

  • Adobe Dreamweaver: To make sure your files work properly, delete Dreamweaver content, copy your content from the WordPress editor, and paste it into the Dreamweaver file.
  • Microsoft FrontPage: Do not use built-in templates. Avoid Internet Explorer-specific code.

Acceptable External Editors

The Text Editor Section of the Glossary recommends using the following external editors:

  • BBEdit
  • Boxer Text Editor
  • Coda
  • Codelobster
  • Crimson Editor
  • EditPad
  • EditPlus
  • Editra
  • emacs
  • Fraise
  • gedit
  • JEdit
  • Kate
  • Komodo Edit
  • Kwrite
  • Notepad++
  • phpDesigner
  • pico
  • PSPad
  • Smultron
  • SubEthaEdit
  • TextEdit
  • TextMate
  • TextPad
  • TextWrangler
  • UltraEdit-32
  • vim
  • Notepad2 (Windows, Freeware)
  • WebTide Editor.

includeonlydiv style=clear:both; background-color:#EEEEFF; border:1px solid #CCCCCC; color:#000000; padding:7px; margin:0.5em auto 0.5em auto; vertical-align:middle;This article is marked as in need of editing. You can help Codex by editing it./div/includeonlynoinclude


This Template is used by Codex:Template Messages.


pre 检查到模板循环:模板:Message /pre