WordPress.org

Ready to get started?Download WordPress

Forums

Using the image caption as the title in slimbox (1 post)

  1. vikkineal
    Member
    Posted 1 year ago #

    Hi there

    I've found the following function to automatically apply the rel, "lightbox-gallery" to all my images that have been uploaded to pages using a particular template.

    However, when clicking on the images, the slimbox displays the post title as the 'title' of the slimbox rather than the caption/title that was entered on the image itself.

    How can I grab the image title instead?

    //lightbox
    add_filter('the_content', 'my_addlightboxrel');
    function my_addlightboxrel($content) {
           global $post;
           $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
           $replacement = '<a$1href=$2$3.$4$5 rel="lightbox-gallery" title="'.$post->post_title.'"$6>';
           $content = preg_replace($pattern, $replacement, $content);
           return $content;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags