Support

Account

Home Forums General Issues The right way to use ACF in a theme

Solved

The right way to use ACF in a theme

  • Hey,

    I’m a little bit confused about what is the right way to using ACF in a theme? I can get some information from here: https://www.advancedcustomfields.com/resources/including-acf-in-a-plugin-theme/

    But it isn’t clearly enough for me.

    STEP 1: Download a copy of the plugin
    –> yes I do it

    STEP 2: Copy the plugin to your theme / plugin
    –> the unpacked plugin ZIP file or the packed plugin ZIP file?

    STEP 3: Include the main plugin file
    –> the main plugin file or files at get_stylesheet_directory() . '/acf/';?

    STEP 4: Customize the directory and path settings
    –> yes it’s possible in this way:

    // 1. customize ACF path
    add_filter('acf/settings/path', 'my_acf_settings_path');
     
    function my_acf_settings_path( $path ) {
     
        // update path
        $path = get_stylesheet_directory() . '/acf/';
        
        // return
        return $path;
        
    }
     
    
    // 2. customize ACF dir
    add_filter('acf/settings/dir', 'my_acf_settings_dir');
     
    function my_acf_settings_dir( $dir ) {
     
        // update path
        $dir = get_stylesheet_directory_uri() . '/acf/';
        
        // return
        return $dir;
        
    }

    STEP 5: Loading the fields via PHP
    –> include_once( get_stylesheet_directory() . '/acf/acf.php' );

    What is located in the folder ../my-theme/acf/[???]. It’s the packed or the unpacked ZIP file? I think the unpacked plugin ZIP file of the ACF plugin. But it should be the complete files and folders of the plugin? I’m asking, because in STEP 3 it calls “plugin main file” and not “files”.

    My problem is, if I following this steps, the ACF plugin dosen’t work without the manually uploading and activation of this plugin at the wordpress plugin page.

    What is the right way to use ACF in a theme?

  • This reply has been marked as private.
  • Ok, I have answered the question by myself. The mistake was the missing include ACF plugin main file.

    I could solved all of my issues with including this path:

    include_once( get_stylesheet_directory() . '/inc/plugins/acf/acf.php' );

    So this is the right way:

    STEP 1: Download the ACF PRO plugin ZIP file

    STEP 2: Unzip the ACF PRO plugin ZIP file

    STEP 3: Upload the unzipped ACF PRO package to your theme materials folder like ../your-theme/inc/plugins/acf/[here is the unzipped package located]

    STEP 4: Add the following code to your theme functions.php to load the ACF PRO plugin from the theme folder: include_once( get_stylesheet_directory() . '/inc/plugins/acf/acf.php' );

    STEP 5: Add the “1. customize ACF path” and “2. customize ACF dir” code from my first post to the functions.php and change the path to your theme located ACF PRO folder.

    STEP 6: Add the following code to your theme functions.php to load your custom field groups, if you want to work with all the fields from the PHP exported file
    include_once( get_stylesheet_directory() . ‘/inc/acf-field-groups.php’ );

    This is the best way to add ACF PRO to your theme, without installing the plugin in the main way by the user. So the user will get no notice about a newer version of ACF and the theme developer can control the ACF version with the included ACF theme folder.

    This is great 🙂

  • Hi wootimes
    I have tried your method exactly but still I am not able to find ‘Custome Fields’ tab in the wordpress backend. Please suggest.
    And in Step 5, what do you mean by ACF PRO folder, is it the same pro folder inside the acf folder which I have uploaded in step 3?

  • @navdeep_ebizon Yes it’s the same folder to the uploaded ACF Pro directory. That’s https://wphave.de/acf-plugin-im-eigenen-theme-oder-plugin-als-framework-einbetten/ all you have to do.

  • I have uploaded and installed this plugin in a theme folder. Now I want to put license key for regular updates. Could you please suggest me a proper way to put license key?

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.