Support

Account

Home Forums General Issues PHP as CSS with ACF field Reply To: PHP as CSS with ACF field

  • It seems like the Advanced Custom Fields (ACF) functions (the_field and get_field) are not available in your PHP file because it’s not part of the WordPress loop. To use ACF functions outside the loop, you need to include the ACF functions file and initialize ACF.

    Add the following lines at the beginning of your dynamic.php file to include the ACF functions and initialize ACF:
    <?php
    header(‘Content-Type: text/css’);

    // Include ACF functions file
    include_once($_SERVER[‘DOCUMENT_ROOT’] . ‘/path/to/your/wp-load.php’);

    // Initialize ACF
    acf()->initialize();
    ?>