• Resolved lightningman

    (@lightningman)


    Hi,

    I need help with setting the title attribute of each slide in the slider to the post title. I have this code so far:

    
        function metaslider_add_rel_attribute_to_images($attributes, $slide, $slider_id) { 
            $attributes['title'] = get_the_title();
            return $attributes; 
        } 
        add_filter('metaslider_flex_slider_image_attributes', 'metaslider_add_rel_attribute_to_images', 10, 3);
         

    I would appreciate any help or examples on this as I am unsure of how to properly call this function. Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi,

    You likely need to pass in the post to get_the_title(). Have you tried outputting it to the page to see what is returned?

    echo get_the_title()

    You might also want to var_dump() the global $post to see if that is available.

    let me know if that helps.

    Thread Starter lightningman

    (@lightningman)

    Hi,

    Thanks for your reply. When I echo get_the_title() I get the post title.

    Do I need to call this function metaslider_add_rel_attribute_to_images() and if so, which parameters do I use for $slide and $attributes? The developer api docs say it takes in an array of slide data for $slide but I’m not sure what that refers to.

    Thanks

    You’re doing it right. What’s the image title showing?

    Thread Starter lightningman

    (@lightningman)

    I’m getting the correct image title but now it only shows one slide, not the whole slideshow

    Hi,

    That could be many things. Do you see any errors in the browser console? If you can share a link I can take a look.

    Thread Starter lightningman

    (@lightningman)

    Hi,

    I didn’t receive any errors in the console. However, I was able to get it working.

    My last question is what indicates where the add_filter will be echoed? For instance, I had the default <?php do_shortcode ?> with my slider ID originally, but then the add_filter generated another slider at the bottom of the page. How do I control where on the page this is generated or should I stick with the do_shortcode but hide the duplicate slider somehow? Hope this makes sense.

    Thanks!

    Hi,

    You shouldn’t be using add_filter to echo or show any code. It should only be used to filter data as it passes through the application.

    I’ll mark this issue as resolved but feel free to continue replying.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Image attributes developer API help’ is closed to new replies.