It’s no secret that adding in custom fields functionality to a premium theme (if you’re a premium theme developer) is sometimes a pain in the ass, especially if you’re not using some kind of third party custom fields framework.
The Advanced Custom Fields plugin for WordPress gives you unrivalled custom fields functionality for an alarmingly low price of $0. There is also the option of buying addons for the plugin which cost $25 each and allow for unlimited use/bundling with a plugin.
The plugins I strongly advise you buy are the Repeater Field and Flexible Content Field. I own all of the additional addons, at $25 they’re a steal but these are the two that you definitely need to buy (or if you’re on a budget the repeater field at the very least).
While ACF doesn’t support bundling out-of-the-box, the author Elliot Condon allows for the plugin to be embedded as well as your purchased premium addons without buying additional licences. Please note that you are not allowed to bundle premium plugins within a free theme or plugin, however if you are selling a theme or plugin, you are allowed as long as you stipulate to the end user that distributing the premium plugins is not allowed in any way.
So lets get too it.
Step #1
You will want to visit the TGM Plugin Activation site and follow the prompts to download their handy and essential activation class, here. This class will allow us to bundle the ACF plugin in our premium theme.
Step #2
Extract the file, “class-tgm-plugin-activation.php” and place it into the root directory of your theme: wp-content/themes/theme-name/
At the top of your functions.php file (located in the root directory of your theme) add this to the very top below the opening PHP tags:
require_once ‘class-tgm-plugin-activation.php’;
This will include the activation class and lead us onto step #3.
Step #3
At the bottom of your functions.php add in the following code (before the closing PHP tag, if you have one). This code does not factor in using premium functionality like the Repeater Field, Flexible Content Field or Options Field, but the code is essentially the same, just add however many additional array entries below to bundle. ACF 4 removed the functionality from the plugin and broke it out into separate plugins to comply with WordPress plugin repository rules.
Step #4
After you’ve added in all required fields locally or on your staging environment, export them as PHP and paste in the exported code where the plugin tells you too. Voila, you’ve just bundled ACF with your theme and added in the needed fields.
Hi there:
thanks for this info, I plan on including the ACF plugins in a ThemeForest theme and am sure this will be useful.
However I noticed that Elliott added a feature called ACF Lite Mode:
http://www.advancedcustomfields.com/resources/getting-started/including-lite-mode-in-a-plugin-theme/
What is your experience with this? Does it work in tandem or cancel out your instructions? Thanks a lot for your insight. Regards,
-JP
JP,
Lite mode is good and pretty much removes most steps surrounding the bundling of ACF into your theme, however there is one severe limitation for some this might not be a problem, but ACF 4 broke out the premium addon functionality into additional plugins (Repeater Field, Flexible Content Field) which means if you need repeater functionality for example, you can’t have it.
Using the TGM class means you can bundle not only ACF, but also bundle the additional premium addon plugins as dependencies in your theme and you get the functionality.
So I would definitely use lite mode if none of the premium functionality matters, else-wise, use the instructions above but also bundle in those other dependencies for the functionality; repeater, flexible, options, etc.
Hi Dwayne:
That’s exactly the kind of detailed answer I was hoping for. I do indeed use both Repeater and Flexible Content fields so I’ll be taking advantage of your technique.
Thanks for sharing, you’ve saved me a ton of time and headache.
With the Advanced Custom Fields, I can make it easier to create fields that are not enough in the WordPress post pages, as we want. For example, I need additional fields, for example, subtitles, city names and so on.