Check The Availability of ACF Plugin

Quick Summary
- Wrap ACF output in a function_exists() check for the_field, so templates skip it rather than hitting a fatal error when ACF is off.
- The same check works in functions.php, for example around an ACF options page, and class_exists() on the ACF class is a common alternative.
- The check only confirms ACF is active, not that a field has a value, so test what get_field() returns for that.
Templates that call Advanced Custom Fields (ACF) functions such as the_field() or get_field() stop with a fatal error if the ACF plugin is deactivated, because those functions no longer exist. Wrapping your ACF output in a check keeps the rest of the page working. On a theme built around ACF, thin helper functions and an admin notice take the same idea further.
<?php if( function_exists( "the_field" ) ): ?>
//DIV BLOCK
<?php endif; ?>How it works
function_exists( "the_field" ) returns true only when ACF is loaded. Replace the //DIV BLOCK line with the markup and ACF calls you want to protect; when the plugin is off, everything between if and endif is skipped. The snippet uses PHP’s alternative if: … endif; syntax, which reads well in template files that mix PHP and HTML.
- You can use the same check in your theme’s
functions.phpbefore calling ACF functions there, for example around registering an ACF options page. class_exists( 'ACF' )is another common way to test for the plugin.- The check only tells you that ACF is active. It doesn’t tell you whether a field has a value; test what
get_field()returns for that.
Related articles
- an ACF Relationship loop wrapped in this check: a full template example that uses it
