• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

Howto: Bundle the Advanced Custom Fields into your premium WordPress themes

General · October 22, 2012

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.

Dwayne

Leave a Reply Cancel reply

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
JP
JP
9 years ago

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

0
Dwayne
Dwayne
Author
9 years ago

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.

0
JP
JP
9 years ago

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.

0
Pabrik Pintu
Pabrik Pintu
3 years ago

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.

0

Primary Sidebar

Popular

  • I Joined Truth Social Using a VPN and Editing Some HTML to Bypass the Phone Verification
  • Testing Event Listeners In Jest (Without Using A Library)
  • Thoughts on the Flipper Zero
  • How To Get The Hash of A File In Node.js
  • Waiting for an Element to Exist With JavaScript
  • How To Paginate An Array In Javascript
  • Handling Errors with the Fetch API
  • How To Get Last 4 Digits of A Credit Card Number in Javascript
  • How To Install Eufy Security Cameras Without Drilling or Using Screws
  • Wild Natural Deodorant Review

Recent Comments

  • CJ on Microsoft Modern Wireless Headset Review
  • Dwayne on Microsoft Modern Wireless Headset Review
  • CJ on Microsoft Modern Wireless Headset Review
  • john on Microsoft Modern Wireless Headset Review
  • Dwayne on Why You Should Be Using globalThis Instead of Window In Your Javascript Code

Copyright © 2023 · Dwayne Charrington · Log in

wpDiscuz