I
I
ian142018-03-10 14:54:08
WordPress
ian14, 2018-03-10 14:54:08

How to display the title of an image in WordPress?

Hello. There is a code for connecting a lightbox:

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

Here we go over the post, look for links that contain pictures of the specified formats, add the required class to the link to connect the lightbox. But the question is: how to change the title of the post (title="'.$post->post_title.'") in the existing code to the title of the image that is inside the link?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question