Custom fields

Carbon Fields

Support page Documentation
Go to Carbon Fields
Carbon Fields banner
19th May, 2018

Carbon Fields
By htmlburger

For folks who don’t know, Carbon Fields has been an ACF competitor for the last couple of years. While not as popular, its open source design and developer friendliness has converted many developers over.


Note that this plugin is developer oriented

Functionality chevron-down

There are two ways of installing Carbon Fields – First one is to simply install it from the Plugins directory. The second option is to install it via composer.

The recommended option is to install it via composer. This is pretty simple as long as you follow the instructions correctly. Once installed, you can define fields in your code like this:

add_action( 'carbon_fields_register_fields', 'crb_attach_theme_options' );
function crb_attach_theme_options() {
    Container::make( 'theme_options', __( 'Theme Options', 'crb' ) )
        ->add_fields( array(
            Field::make( 'text', 'crb_text', 'Text Field' ),
        ) );
}

Conceptually, the containers mentioned above are the equivalent of field groups in ACF. You can attach them to posts, custom post types, pages, taxonomies, etc. You can also setup theme options pages such as above.

After pasting that in your functions.php, head over to Sidebar > Theme Options and you’ll get this:

Carbon Fields sample field
Carbon Fields sample field

Now we’ll get that field on the frontend. Paste this somewhere in your template:
<?= carbon_get_theme_option( 'crb_text' ); ?>

This will pull in the text you entered in the field. That’s all to it.


There are more than 20 fields to select from. I’ve made a gist which contains all available fields. Simply drop it into a blank WordPress theme’s functions.php to checkout all fields.

This is how the backend looks like with all field types loaded:

All Carbon fields
All Carbon fields

Note that the complex field(equivalent to the repeat field in ACF) is missing from above. This is a very powerful field via which you can nest fields inside. Just like ACF’s repeater. you can nest unlimited times.

API chevron-down

The API for setting up fields can look tedious but trust me after spending 5 minutes entering the fields, it becomes easy. The methods are pretty straightforward and intuitive.

On a side note, the error messages are pretty helpful. This is what I encountered when I didn’t set the $field_type on a field correctly:

Carbon fields error message
Carbon fields error message

The only issue I found with the API was when pulling the data on the frontend. When you’re gonna write a particular method call lots of times in your php template, it helps if its name is short. You’ll be using a lot of <?= carbon_get_the_post_meta($field_name); ?> throughout your templates.

For comparision, ACF’s equivalent is simply <?= get_field($field_name); ?>

Overall, the API could be more concise but its definitely ahead of the rest of the WordPress ecosystem.

Documentation chevron-down

Documentation is well organized with a list of field types and their available options along with some examples are given in the sidebar of the docs page as well as guides on setting up.

The organization of articles could be better but this isn’t bad for a free plugin.


Other than the official documentation, google searches for Carbon field issues comes up dry. The dev community is pretty active on Glitter and Github though, so you should be able to get help from there.

Support chevron-down

There is no official support but Carbon Fields has their own GitHub repository where you can report bugs or new features. They also have a Glitter channel which is pretty active.

Overall, development on Carbon Fields is active with new updates being pushed regularly.

TLDR chevron-down

Overall, I can’t seem to help but categorize Carbon Fields as a plugin for more advanced developers due to its use of composer(its not even a plugin if you install via this) and the old school way of defining fields inside your code.

This plugin has all the basic fields for a custom fields plugin as well as the complex field which supports unlimited nesting. The API calls can be a bit clunky and there’s no GUI editor for adding fields.

Leans more toward advanced developers who have a more structured process of building themes.

Technical Report chevron-down

Lines of code 12,716
Cyclometric complexity(CC) 5.86
Code violations

(0 criticals, 14 errors) - 43 errors

Uses custom Db table? No
CC Chart

Internally, it stores data inside postmeta for fields inside posts, termmeta for terms fields and so on.

With a CC of 5.83 which is below the baseline for most WordPress plugins and a loc of 12,716 lines, Carbon fields is a well maintained plugin with solid coding standards.

Data generated from Phpmetrics. Although the data found through our research has been produced and processed from sources believed to be reliable, no warranty, expressed or implied, is made regarding accuracy, adequacy, legality or reliability of any information.

Features

Drag and drop builder No
Conditional logic Yes
Multisite ready Yes
WPML compatible Yes
Gutenberg ready Yes

Verdict

A very well designed open-source custom fields plugin for WordPress. Highly recommended for advanced developers.

  • Well written documentation and an active github repository.

  • Everything is done programmatically. This also means writing a lot of code for defining fields.

  • Writing field definitions can be cumbersome.

4/5

star-full star-full star-full star-full star-empty

Helpful disclosure

Our works are supported by earning an affiliate commision
when readers choose to purchase a plugin based our reviews.