Categories
Pro Tips

Hiding Advanced Custom Fields

Today's tip of the day is for the Advanced Custom Fields plugin.

Table of Contents
  1. The Code

Today’s tip of the day is for the Advanced Custom Fields plugin.

For more, take a look at our well-reviewed article on Advanced Custom Fields Front-end Form

In the two snippets below, I show you how to hide an ACF field either on the front-end when using the acf_form() function or in the back-end and limit the field to edited and filled only by users that are administrators.

For more information, don't miss our popular article on The Importance of Customer Support: Building a Knowledge Base for Your Plugin

The Code

add_filter('acf/prepare_field/name=acf_field_slug', function ($field) {
  return false;
}, 10, 1);
add_filter('acf/prepare_field/name=acf_field_slug', function($field) {
  if(is_admin()) {
    return $field;
  }
  return false;
}, 10, 1);
Ready to continue learning? Check out our helpful article on Cleaning Unused ACF Custom Fields and Resetting Taxonomies

Leave a Reply

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