When I build client websites that require added functionality, such as widgets to the homepage layout, adding custom image sizes or loading google fonts, I use a Site-Specific Plugin.
A Site-Specific WordPress plugin is a specific place to add code snippets that you find on the web that performs functions that are not theme related.
Time and time again, you will read “how-to” articles related to WordPress all around the web where we share snippets and suggest that you add them into your theme’s functions.php file. These snippets are not huge enough to be justified as plugins of their own, but some of them are certainly great to add specific functionality to a site that is not theme-dependent such as redirecting users to a random post. Whereas other functions can be key to your specific site such as Custom Post Types.
This is when you need to add a site-specific plugin which essentially will serve as the same purpose of your theme’s functions.php file, but it will allow you to retain all these functionality when you are changing themes.
The code below will help you create your own site-specific plugin. You only need to add lines 1 through 22 to create the plugin, below this is where you would add the code specific to your site.