Using code snippets in WordPress
The easiest way to add custom code snippets to your WordPress website is by combing them all into a custom plugin, or by using a code snippet plugin like Code Snippets or similar.
Creating a custom WordPress plugin to add custom code
A custom plugin can be created by adding a new file in the plugins directory “/wp-content/plugins” called “importwp-custom.php”, and add the following code to the top of that file.
<?php
/**
* Plugin Name: Import WP - Custom code
* Plugin URI: https://importwp.com
* Description:
* Version: 1.0.0
* Network: True
*/
// TODO: Add your custom code here
With the plugin header added to your file, a new plugin should then be visible when browsing the installed plugins page in your WordPress admin area named “Import WP – Custom code”, where it can be activated.
Now you can append any custom code snippets this file after the previously added plugin header code.