How to define your ACF license key in code

Developers that look after more than a few sites will know that managing license keys for commonly used plugins can actually be quite a painful task.

Sure, pasting in a license key isn’t hard, but it’s surprisingly easy to forget and when moving sites between new domains and/or staging/live environments the key can sometimes get lost.

Fortunately, ACF have finally introduced the ability to define your license key in your code – simply put it in once and forget it. Before proceeding, you’ll need to make sure you are on at least version 5.11 of ACF PRO.

Here’s the code:

ACF will now look for and use a PHP constant named ACF_PRO_LICENSE, which you can define with your license key.

define('ACF_PRO_LICENSE', 'yourkeyhere' );

This should go in your wp-config.php file or any other file that runs before the ACF plugin does. We’d recommend sticking with wp-config.php though, as it’s a good home for any constants and easy to remember.

Always remember to .gitignore your wp-config.php file if you are using version control. Even in private repos it’s not wise to share secrets.