How to add multiple featured images to post/page without a plugin

The best advice is to use the plugin. I can’t think of any reason to rebuild functionality that already works well and exists. If you absolutely need this functionality in the theme, you can include the code from the plugin into your theme by removing the header in the plugin’s main file and requiring it in your theme’s functions.php file.

Please bear in mind that this is NOT considered as “best practice” and there are a couple of other steps that you will need to take to really make this work well:

  1. Change the name of all the functions. Adding a prefix like “myplugin_” to all functions should work well. Also, you will want to use this custom prefix on all global variables, class names, settings, localization slugs and anything else that WordPress might “see”. This will avoid clashes in the event that the actual plugin is ever installed.

  2. load_plugin_textdomain() ahould be changed to load_theme_textdomain().

  3. plugins_url() will need to be changed to get_template_directory_uri().

  4. paths will need to be addressed.

At the end of the day, I would strongly urge you to allow your theme to support the plugin and degrade gracefully if the plugin is not installed.