• Resolved Mayeenul Islam

    (@wzislam)


    I don’t want to use Carbon Fields as a plugin. I want to include it in my theme. CF’s Getting Started guide doesn’t cover it! So I explored my way:

    I’ve downloaded the plugin (version 1.0), and extracted it. In my theme I placed the folder is in here:
    my-theme/libs/carbon-fields/

    Now in my functions.php, I put the following:

    function carbon_fields_spl_autoload_register( $class ) {
    	if ( stripos( $class, 'Carbon_Fields') === false ) {
    		return;
    	}
    
    	$file_path = get_template_directory() . '/core/' . str_ireplace( 'Carbon_Fields\\', '', $class ) . '.php';
    	$file_path = str_replace( '\\', DIRECTORY_SEPARATOR, $file_path );
    	include_once( $file_path );
    }
    
    spl_autoload_register( 'carbon_fields_spl_autoload_register' );
    
    include_once get_template_directory() .'/libs/carbon-fields/carbon-fields.php';
    include_once get_template_directory() .'/libs/carbon-fields/core/functions.php';

    But it’s not working and showing me warnings, and a Fatal Error:

    Fatal error: Class ‘Carbon_Fields\Helper\Helper’ not found

    https://www.ads-software.com/plugins/carbon-fields/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author htmlBurger

    (@htmlburger)

    Hi Mayeenul!

    The best way to use the Carbon Fields in the theme is to load it with Composer – https://getcomposer.org. To do that, you should add htmlburger/carbon-fields as a composer dependency (in the composer.json file), then load Composer’s autoload file (for example in your theme functions.php).

    If you’re having difficulties with that approach, you should try including the Carbon Fields plugin file in your theme functions.php – it will setup the autoloading for you. Example:

    require(__DIR__ . '/libs/carbon-fields/carbon-fields-plugin.php');

    Please, let us know if you’re having further issues.

    Thread Starter Mayeenul Islam

    (@wzislam)

    Pardon me. I’s in hurry.
    I thought I could try using Carbon Fields for my new project. But your support was slow, and I couldn’t make it using the docs.
    So, I switched to another fav. Metaboxes Framework.

    May be next time.

    It’d be better if your doc can be a bit clearer about it. Good luck for the nice job. Keep the spirit, and Carbon Fields is going to be the next big thing. <3

    Plugin Author htmlBurger

    (@htmlburger)

    Hi Mayeenul,

    We apologize we could not reply sooner.

    Also, we’re constantly working on improving the documentation, and we’ll soon introduce some more articles and guides that will be helpful when you use Carbon Fields for the first time.

    And we hope Carbon Fields will be the right library for you next time.

    Good luck with your project! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to embed/include Carbon Fields in a theme’ is closed to new replies.