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();
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.