One method of making changes to your site using code snippets is through the use of the theme functions.php file. From the WordPress Codex:
The functions file behaves like a WordPress Plugin, adding features and functionality to a WordPress site. You can use it to call functions, both PHP and built-in WordPress, and to define your own functions.
Most themes include the functions.php file in the main directory, e.g., Twenty-Twelve theme has one under
Because this file needs to contain PHP code, it should start with an opening PHP tag:
Any custom functions can be placed below this, but ensure there are no extra
<?php tags when you’ve pasted your snippet!
We recommend to never use the editor in WP Admin to edit functions.php. If you make a mistake you may be unable to correct it if the admin area cannot load due to an error. Instead use and an FTP client or your host’s file manager.
- Download the theme functions.php file to your computer from the theme directory using an FTP client.
- Make changes using a simple text editor, such as Notepad or a code editor.
- Upload the modified file back to the theme directory using your FTP client.
Debugging ↑ Back to top
To troubleshoot any errors after adding code, you can temporarily enable WP_DEBUG mode to see what has gone wrong and correct mistakes.
Child themes ↑ Back to top
To keep changes safe from theme updates, it is recommended that you create a child theme with its own functions.php instead of editing the parent theme. The theme vendor may have additional instructions on how to do this in their documentation.