Answer the question
In order to leave comments, you need to log in
How to Display Header Image in WordPress?
Hello! I am using lightbox script to enlarge images. For the code to work, the functions.php file contains a code that inserts "title" into the "a" tag. However, it does not insert the title of the image, but of the article. As a result, when the images are enlarged, the same name is shown under them.
The code itself:
function addrellightbox($content) {
global $post;
$pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
$replacement = '<a$1href=$2$3.$4$5 rel="lightbox" class="lightbox" title="'.$post->post_title.'"$6>';
$content = preg_replace($pattern, $replacement, $content);
return $content;
add_filter('the_content', 'addrellightbox');
}
<a href="/full.jpg" rel="lightbox" class="lightbox" title="Заголовок статьи">
<img class="wp-image" title="Заголовок изображения" src="/640x480.jpg" alt="Заголовок изображения" width="640" height="480">
</a>
Answer the question
In order to leave comments, you need to log in
Well, everything is correct, you have the title of the article: $post->post_title
As far as I remember, lightbox does not need such dances with a tambourine, it substitutes rel itself. If not, then it is enough to specify the class when inserting a picture in the editor, and the title is also written there. If it is present, then the VI itself inserts it into the img tag. I'm not sure about the anchor.
Otherwise, your function needs to be completed, dragging the image title by the attachment ID and inserting it into the anchor title.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question