Support

Account

Home Forums ACF PRO How to correctly set paths if ACF plugin is added to a theme dir

Solved

How to correctly set paths if ACF plugin is added to a theme dir

  • I want to include this plugin as part of my theme, and when including the plugin in my theme directory, paths get screwed up on the admin side with no CSS or JS getting pulled in correctly.

    I was able to get this working by hardcoding my paths/dirs, but not with the function as recommended by the v5.0 documentation. what is wrong with my function that’s causing incorrect paths to be used?

    Modifying these 3 lines directcly on acf.php works:

    			'basename'			=> 'acf/acf.php',
    			'path'				=> '/Users/timmyblog/Sites/cortex.covertnine.com/wp-content/themes/cortex/admin/acf/',
    			'dir'				=> 'http://localhost:8888/cortex.covertnine.com/wp-content/themes/cortex/admin/acf/',
    

    but when I setup the functions.php file with the following:

    function acf_settings_path( $path ) {
        return get_template_directory() . '/admin/acf/';
    }
    add_filter('acf/settings/path', 'acf_settings_path');
    
    function acf_settings_dir( $dir ) {
        return get_template_directory_uri() . '/admin/acf/';
    }
    add_filter('acf/settings/dir', 'acf_settings_path');
    

    it does not work.

    Any suggestions on how to get that working properly?

  • Oops! I see my mistake. I had acf_settings_path included twice. Changed that to dir and it worked. Here’s the working code in case anyone else has this issue:

    function acf_settings_path( $path ) {
        return get_template_directory() . '/admin/acf/';
    }
    add_filter('acf/settings/path', 'acf_settings_path');
    
    function acf_settings_dir( $dir ) {
        return get_template_directory_uri() . '/admin/acf/';
    }
    add_filter('acf/settings/dir', 'acf_settings_dir');
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to correctly set paths if ACF plugin is added to a theme dir’ is closed to new replies.