Title: Function only for widgets (lightbox data attribute)
Last modified: August 30, 2016

---

# Function only for widgets (lightbox data attribute)

 *  [naastje](https://wordpress.org/support/users/naastje/)
 * (@naastje)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/function-only-for-widgets-lightbox-data-attribute/)
 * Hi there guys,
 * I wonder if there is a way to add function only to widgets.
 * I was planning using blueimp lightbox for my images, but since it includes all
   images from the page into the same lightbox I wanted to split images from widgets
   and images from page/post
 * I used this code
 *     ```
       function add_rel_to_gallery($link) {
       return str_replace('<a href=', '<a data-gallery="#blueimp-gallery-test" href=', $link);
       }
       add_filter( 'wp_get_attachment_link', 'add_rel_to_gallery' );
       ```
   
 * to add the data attribute to media links, well that works, but can you add this
   function only to widget areas or only to posts and pages?

The topic ‘Function only for widgets (lightbox data attribute)’ is closed to new
replies.

## Tags

 * [data-attribute](https://wordpress.org/support/topic-tag/data-attribute/)
 * [function](https://wordpress.org/support/topic-tag/function/)

 * 0 replies
 * 1 participant
 * Last reply from: [naastje](https://wordpress.org/support/users/naastje/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/function-only-for-widgets-lightbox-data-attribute/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
