On click do something else

The on_click filters are powerful filters to change your thumbnail and slide link actions. The new Lazyest Slides thickbox plugin uses this filter to show the popup. Below, I'll explain two examples. One to change the link in posts, and the other to change the link title.

The on_click filters normally return what you have selected in Lazyest Gallery Settings for On Click for Thumbnails and Slides. The script stores the parameters in an array.

  'href' => $address, // the url for ( slide, full size image, or # )
  'class' => $class, // the link class e.g. thickbox
  'rel' => 'nofollow', // set to lightbox[foldername] when lightbox is selected
  'title' => $title, // escaped caption of image name
  'id' => $id // image name where spaced are replaced by underscores

Lazyest Gallery offers two filters to change the values in this array.
'lazyest_thumb_onclick' and 'lazyest_slide_onclick' and they come with two parameters; the on_click array and the image object currently being displayed.

Change the url and class in posts

The following example shows how to change the address and class for slides in posts shortcodes.
Baff, has inserted many slides in posts. He wants to redirect clicks on slides in post to the slide view pages in the gallery, but when someone clicks on a slide or thumb in the gallery page, a full image should display in a thickbox popup.
Baff selected Show full size image in Thickbox in Lazyest Gallery Settings for thumbnails and slides. For posts, apply the following filter:

function my_slide_onclick( $onclick, $slide ) {
  global $lg_gallery;
  // check if we are on the gallery page
  if ( $lg_gallery->is_gallery() )
    return $onclick; // return default on_click settings
  $onclick['href'] = $slide->uri( 'widget' ); // change the url
  $onclick['class'] = 'slide'; // change the class
  return $onclick;
add_filter( 'lazyest_slide_onclick', 'my_slide_onclick', 10, 2 );

This function checks first if we are on the gallery page. If so, it will return the default on_click settings. If not, the url is changed to the slide view url in the gallery. The parameter is set to 'widget', because clicks on widgets always go to the gallery page. The class is set to 'slide' to override the thickbox setting.

Change the link title

Christoph asked if he could have the description in the 'pop up' when your mouse pointer hovers over the image link for thumbnails. Most browsers show the link title in this popup. We can easily replace the link title (caption) with the description using the following filter:

function my_thumb_on_click_popup( $onclick, $thumb ) {
  $onclick['title'] = esc_attr( strip_tags( ( $thumb->description() ) ) );
  return $onclick;
add_filter( 'lazyest_thumb_onclick', 'my_thumb_on_click_popup', 10, 2 );

Implement these filters by copying the functions to your theme's functions.php.

3 thoughts on “On click do something else

  1. Pingback: How to add prettyPhoto support to Lazyest Gallery | Brimosoft

  2. Christoph


    thank your for advice! I have created a child theme for twenty eleven and added the code to functions.php, but nothing changed. Is it possible to show both captions and descriptions?

    Best regards,

Comments are closed.