Home Forums General Issues Accessing ACF field with JS


Accessing ACF field with JS

  • Dear all,

    The purpose is to display ACF fields as captions for pics.
    I have a gallery, created with jQuery masonry image gallery and lazyload, and jQuery Colorbox. I want the title in the colorbox to be a value contained in a ACF field of the media.

    By default, colorbox uses the title of the media (file “jquery-colorbox-wrapper.js”)
    var $image = jQuery(link).find(“img:first”);
    //check if the link has a colorbox class
    var $linkClasses = jQuery(link).attr(“class”);
    //the title of the img is used as the title for the Colorbox.
    var $imageTitle = $image.attr(“title”);
    if ($imageTitle !== undefined) {
    ColorboxLocal.colorboxTitle = $imageTitle;

    Using firefox debugger I can see that there is no attribute corresponding to acf fields for the object ┬žimage. Do you know which way I could use to access these fields ?
    Thank you by advance

  • I don’t know a lot about the jQuery plugins your using, but if you want ACF values in your code somewhere then you need to put them there. I am assuming that there are “data-” attributes that you can add to some element that are used by one of these plugins.

    If the image gallery plugin you mentioned is this one then I would start by looking at the documentation for that plugin if there are any filters that will let add these custom values.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.