acf_plugin_dir_url()
This function will calculate the url to a plugin folder. Different to the WP plugin_dir_url(), this function can calculate for urls outside of the plugins folder (theme include).
No Hooks.
Returns
String. The plugin directory path.
Usage
acf_plugin_dir_url( $file );
- $file(string) (required)
- A file path inside the ACF plugin to get the plugin directory path from.
Changelog
| Since 5.6.8 | Introduced. |
acf_plugin_dir_url() acf plugin dir url code ACF 6.8.8
function acf_plugin_dir_url( $file ) {
$path = plugin_dir_path( $file );
$path = wp_normalize_path( $path );
// check plugins.
$check_path = wp_normalize_path( realpath( WP_PLUGIN_DIR ) );
if ( strpos( $path, $check_path ) === 0 ) {
return str_replace( $check_path, plugins_url(), $path );
}
// check wp-content.
$check_path = wp_normalize_path( realpath( WP_CONTENT_DIR ) );
if ( strpos( $path, $check_path ) === 0 ) {
return str_replace( $check_path, content_url(), $path );
}
// check root.
$check_path = wp_normalize_path( realpath( ABSPATH ) );
if ( strpos( $path, $check_path ) === 0 ) {
return str_replace( $check_path, site_url( '/' ), $path );
}
// return.
return plugin_dir_url( $file );
}