Add rel attribute to lightbox in WordPress
Add this code snippet to functions.php see above topic, after which the attribute will be added to all links in the pictures rel=”lightbox”. Pay attention to that, what in 5 line, this attribute can always be changed, for different modal window scripts.
1 2 3 4 5 6 7 8 |
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" title="'.$post->post_title.'"$6>'; $content = preg_replace($pattern, $replacement, $content); return $content; } |
And for those who have their weight in gold and projects for yesterday, сделать модальные окошки в wordpress можно при помощи плагина FancyBox for WordPress. Для корректной работы плагина заходим в его настройки и нажимаем Revert to defaults, после чего жмем Save Changes и плагин начинает работать для всех картинок.
Use the suggested code snippet in your plugins.
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.