Hi ACF team,
Does ACF allow me to create a custom field where I can add js code to my posts? Of course, each post has its own js code and I’m not talking about a global js I can easily add to my site.
If so, what’s the field type and any details would be greatly appreciated!
Thank you!
I use a textarea field. Outside of “The Loop” you need to get the post id to your when getting fields.
$post_id = 0;
$queried_object = get_queried_object();
if (is_a($queried_object, 'WP_Post')) {
$post_id = $queried_object->ID;
}
get_field('field_name', $post_id);