I see that many users use child themes when they want to add code snippets to the site, but I can’t agree that this is the correct way to do it. The purpose of the child theme is to overwrite templates and some parts of the central theme, so using child themes to keep code snippets is redundant.
It is much better to use a custom plugin instead. This has many benefits.
First – you don’t touch theme functionality and will not break it
Second – you can use it with any theme
There is also one myth that when you use many plugins, it will slow down the site. But from the technical side, there is no big difference if you put custom code in the theme or in the plugin
Here is an example of a clean plugin for snippets
<?php
/**
* Plugin Name: Greenshift Code Snippet
* Plugin URI: https://greenshiftwp.com
* Description: This plugin adds a custom snippets to your site
* Version: 1.0
* Author: Wpsoul
* Author URI: https://greenshiftwp.com
* License: GPL2
*/
//Put code below
simply put it in a text file and save it as greenshift-code-snippet.php, then upload file in Plugins – add new and activate. Now, you can edit the code of a file in the Plugins – editor, or install any File manager plugin, or edit it from the hosting panel/FTP