Skip to content

Instantly share code, notes, and snippets.

@unculturedswine
Created August 31, 2022 16:46
Show Gist options
  • Save unculturedswine/1c9588022dff16f2cfb64c910f97eeee to your computer and use it in GitHub Desktop.
Save unculturedswine/1c9588022dff16f2cfb64c910f97eeee to your computer and use it in GitHub Desktop.
How to include the Advanced Custom Fields plugin inside your own plugin.
<?php
// Define path and URL to the ACF plugin.
// Including in a theme uses get_stylesheet_directory on line 4, but for a plugin you need a different call.
// This is the correct way to call the ACF plugin inside a plugin
define( 'MY_ACF_PATH', plugin_dir_path( __FILE__ ) . '/includes/acf/' );
define( 'MY_ACF_URL', plugin_dir_url( __FILE__ ) . '/includes/acf/' );
// Include the ACF plugin.
include_once( MY_ACF_PATH . 'acf.php' );
// Customize the url setting to fix incorrect asset URLs.
add_filter('acf/settings/url', 'my_acf_settings_url');
function my_acf_settings_url( $url ) {
return MY_ACF_URL;
}
// (Optional) Hide the ACF admin menu item.
add_filter('acf/settings/show_admin', 'my_acf_settings_show_admin');
function my_acf_settings_show_admin( $show_admin ) {
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment