Only load ACF on the backend

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.

<?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;
}
view raw functions.php hosted with ❤ by GitHub

Credit Bill Erickson, see https://www.billerickson.net/code/disable-acf-frontend/

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *