Field In A Theme
Carbon Fields allows you to define custom fields inside your theme if you have theme-specific fields that you do not intend to distribute separately:
- Execute
git clone https://github.com/htmlburger/carbon-field-template.git --single-branch --depth 1 includes/my-fieldin your theme dir - Delete the
includes/my-field/.gitdirectory - Add the following to your theme’s composer.json:
"autoload": { "files": [ "./includes/my-field/field.php" ], "psr-4": { "Carbon_Field_YOURFIELDNAME\\": "./includes/my-field/core/" } } - Call
composer dumpautoload - Browse to the
includes/my-fielddirectory - Call
npm install - Edit
includes/my-field/webpack.config.jsand adjust theconst rootvariable to point to the directory of Carbon Fields (e.g.const root = path.resolve(__dirname, '../../vendor/htmlburger/carbon-fields');) - Call
npm run build - You now have a local custom field running from your theme
- If the field is theme-specific and will not be distributed separately feel free to delete the
composer.jsonandcomposer.lockfiles.
