Including ACF in functions.php (WordPress) Including ACF in functions.php (WordPress) wordpress wordpress

Including ACF in functions.php (WordPress)


You need to make sure your includes won't collide with ACF itself or someone else's plugin that also uses it.

if( !class_exists('Acf') )    include_once('external/acf/acf.php' );if( !class_exists('acf_repeater_plugin') )    include_once('external/acf-repeater/acf-repeater.php');if( !class_exists('acf_options_page_plugin') )    include_once('external/acf-options-page/acf-options-page.php');


There are only Four steps to include ACF in functions.php

    /***********************************************************    *               Integrate ACF in theme    ***********************************************************/    // 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() . '/framework/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() . '/framework/acf/';            // return        return $dir;        }     // 3. Hide ACF field group menu item    add_filter('acf/settings/show_admin', '__return_false');    // 4. Include ACF    include_once( get_stylesheet_directory() . '/framework/acf/acf.php' );    // including acf fields    require_once( get_template_directory() . '/framework/acf-fields.php' );