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 when you deactivate the ACF plugin. Those functions no longer exist then. 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
<?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, PHP skips everything between if and endif. 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.php before 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.

Guarding ACF calls like this keeps the themes I build working without the plugin; more on custom WordPress development.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More