Instead of rebuilding similar custom fields in different sites, you can use the Meta Box Builder extension to easily copy them from one site to others with just a few clicks.
Benefits of cloning custom fields from site to sites
Actually, cloning is copying the code of the meta boxes/custom fields group created on a site, then importing it into another site.
On the other hand, you can create a series of custom fields on a local site only with an adequate configuration as you want. Then, import the code of the needed fields to the target sites. It ensures that all of the fields which you import into the sites have the same settings.
Moreover, there is no need to install any extension of Meta Box on the target sites.
There are some benefits of this:
- You may not worry about having the same request for the same fields but configurations are different among projects. You also stop the memory of how you configure fields escapes you, whether it has the error or not.
- It may not waste time anymore in the field configuration with the complex attributions or conditions. You only do it once, and clone to the sites you need. That’ll save a lot of time.
- Your website runs faster because of not installing any plugin or extensions for these custom fields beyond the Meta Box Framework. Meanwhile, you still have the adequacy of necessary custom fields and their configuration on your website.
Here are the tools we need:
- Meta Box plugin: install this plugin on all sites to have a framework to create custom fields. It’s free and available on wordpress.org.
- Meta Box Builder: activate this extension on the original site where you created the custom fields.
Creating field groups and custom fields
If you already have custom fields, you can move to the next step. In case you want to create a sample of custom fields and then paste them into sites, let’s do it.
We have another tutorial for this step, please take a look for more detail here.
For instance, I created a field group like this:
Exporting the code of custom fields
Go back to the field group editor. Press the Get PHP Code button > Generate to generate the code.
Next, click on the Copy button to copy all the code at once.
Remember that this is the code of a field group, so you’re exporting all the custom fields included in this field group.
If your field group includes several custom fields and you want to clone some specific ones only, you need to separate them into different field groups and then export each one.
Importing code to another website
Next, on the website where you want to paste the code, go to Appearance > Theme File Editor and open the
functions.php file to embed the copied code.
Then click on the Update File button.
- There is no need to install the Meta Box Builder on the targeted website, but you must install the Meta Box on this site to make sure that the embedded code can operate.
- In case the target is the original website used to create fields, let’s deactivate Meta Box Builder on this site before embedding its code.
- If the field group IDs are iterated, only the last one is accepted. Therefore, make sure the ID of each field group differs from others so all of them can work.
After embedding the code into another site, the field group with custom fields will display similar to the original site: