You can put small PHP snippets in your theme’s functions.php. That works, but a theme update can overwrite the file, and a PHP error can break the site.
A safer option for many sites is WPCode (Insert Headers and Footers) from WordPress.org. It stores snippets in the database and can disable a snippet if it throws an error.
Install WPCode
- Go to Plugins → Add New.
- Search for WPCode (plugin title often includes “Insert Headers and Footers”).
- Install and activate it.
- Open Code Snippets in the admin menu.
Add a snippet
- Go to Code Snippets → Add Snippet (or Add Your Custom Code).
- Give the snippet a clear title.
- Paste the code.
- Set the type (PHP, HTML, JavaScript, or CSS).
- Enable the snippet and save.
Only add code you trust. WPCode reduces downtime risk; it does not make unsafe code safe.


