Output Advanced Custom Fields Data as JSON in JavaScript Console

01/30/2024
Back to Gists
<?php
/**
 * Output Advanced Custom Fields Data as JSON in JavaScript Console.
 *
 * This code retrieves data from Advanced Custom Fields (ACF) and outputs it
 * as JSON in the JavaScript console for debugging and development purposes.
 *
 * Gist Keywords: wordpress, acf, javascript, debugging
 *
 * @author Knol Aust
 * @version 1.0.0
 */

$data = get_fields();
?>

<script>
    console.log(<?php echo json_encode($data); ?>);
</script>