I use ACF on almost every website I build because it makes it very easy to create intuitive interfaces for custom post meta, and especially for complex template layouts. On the front end, however, I use native WordPress functions to look up post metadata and render templates.
Use the following code to stop ACF Pro from loading on the website front end, giving the site a slight speed boost.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'option_active_plugins', __NAMESPACE__ . '\disable_acf_on_frontend' ); | |
/** | |
* Disable ACF Pro on website frontend. | |
* | |
* Provides a performance boost if ACF frontend functions aren't being used. | |
* | |
* @since 1.0.0 | |
* @link https://www.billerickson.net/code/disable-acf-frontend/ | |
* | |
*/ | |
function disable_acf_on_frontend( $plugins ) { | |
if ( is_admin() ) { | |
return $plugins; | |
} | |
foreach ( $plugins as $index => $plugin ) { | |
if ( 'advanced-custom-fields-pro/acf.php' == $plugin ) { | |
unset( $plugins[ $index ] ); | |
} | |
} | |
return $plugins; | |
} |
Credit Bill Erickson, see https://www.billerickson.net/code/disable-acf-frontend/
Leave a Reply