The most common way to add PHP code to WordPress is via Functions.php file.
To edit Functions.php file you need FTP access.
If you make a mistake while adding PHP code to Functions.php file, your website will stop working.
If it’s stop working, you’ll see a white screen when you access the site via browser.
Instead of making changes directly to Functions.php file, you can use a plugin called Code Snippets.
How to Add PHP Code to WordPress Using a Plugin?
- Download the Code Snippets plugin here.
- Install and activate the Code Snippet plugin.
- Click “Add New” to add a new snippet.
- Once “Add New” page is loaded, you can enter snippet title, actual snippet, description and tags as shown below. In addition, you can also choose where to run these snippets.
- Snippets can be run in following places:-
- Administration area (back-end)
- Both front-end and back-end
- After entering the snippet, click “Save Changes and Activate” button to save and activate the snippet at the same.
- Now the newly entered snippet should be working.
Plugins like Code Snippets provides an easy, clean and simple way to run PHP code snippets on your site.Credits
- Icon by Pixel Perfect