If you edit any code in a plugin or your theme directly, you’ll lose those changes when the plugin or theme has an update. Instead, we can either use a plugin like the Code Snippets or create a functional plugin as described below.
Create a new PHP file in wp-content/plugins/
Create a new file in your wp-content/plugins/ folder called something that describes what you’re doing, with a .php at the end. Maybe add-field-to-post.php or use-meta-in-other-plugin.php
Add the standard plugin header
Just copy and paste the following header and put it at the top of your .php file. Edit the plugin description, author (to you) to better describe what this snippet of code is doing.
<?php
/*
Plugin Name: Customize Other Plugin Output
Plugin URI: https://eventcalendarnewsletter.com/the-events-calendar-shortcode
Description: Changes the output from The Other Plugin using a bit of code
Author: Brian Hogg
Version: 1.0.0
Author URI: http://brianhogg.com
License: GPL2
*/
Add your code underneath
Now just add in the code you were going to copy/paste into your functions.php file below this header. Avoid putting a closing ?> PHP tag at the end to avoid any errors with extra whitespace, which would likely break your theme, RSS feeds, and a bunch of other things.
Activate the plugin
Now just go to Plugins in your WordPress dashboard, and activate that plugin.
Voila! You’ve now created a small functional WordPress plugin that clearly describes what it does, and will not be removed when you update your theme. You can also easily deactivate or delete the plugin if you no longer need that piece of code.