I feel that the best way to add code snippets to your site is through what many developers call a “Site Functionality Plugins.” This is because, unlike a theme’s functions.php file, a custom plugin will never be overwritten when/if you update your theme. Better yet, the plugin’s features are not lost if you decide to change themes.
With only a few exceptions, all code snippets that I will provide on this site are assumed to be added to your Functionality Plugin. Here we will discuss how you can add your code to this plugin. First, the plugin:
[php_tag]
/*
Plugin Name: {domain} Site Functionality Plugin
Plugin URI: https://{domain}/
Description: This plugin implements functionality for the {domain} site.
Copyright: Copyright {yourname}. All Rights Reserved.
Version: 1.0
Author: {yourname}
Author URI: https://{yourdomain}
Text Domain: {text-domain}
Donate: https://davejesch.com/send-me-coffee/
License: GNU General Public License, version 2 http://www.gnu.org/license/gpl-20.0.html
*/
// vvv add your code here
// ^^^ add your code here
In the above code, you will see a few things that need to be replaced
- {domain} – The name of the domain the plugin is for
- {yourname} – You are the developer so put your name here.
- {yourdomain} – Your domain name
- {text-domain} – This is the “text domain”. For more information, see my post about Text Domains.
For the latest updates to this Site Functionality Plugin, you can follow my GitHub repository.