Support

Account

Home Forums ACF PRO How to add custom class to admin_body_class based on ACF field data? Reply To: How to add custom class to admin_body_class based on ACF field data?

  • You are correct that get_field() will not automatically work because you are on the admin side, however, it is possible to pass the post_id you want the value from as a parameter:

    global $post;
    get_field('some_field', $post->id);

    There is however still an issue with that global post. Especially on post creation this might not work properly and another issue is that you could only see results by saving your changes and then refreshing the page.

    My advice is to load some custom javascript in the admin and add/change/remove classes on the admin body using jQuery (or just vanilla).