• Resolved fichter

    (@fichter)


    Hi! Can you please tell me how to customize a thumbnail link? For example i need to add data-fancybox=”testimonials” to activate my fancybox plugin.

    • This topic was modified 1 year, 6 months ago by fichter.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support beatrice12

    (@beatrice12)

    Hello @fichter,

    Thanks for reaching out to us!

    You’ll need to add a small snippet in your child theme’s functions.php file.

    function wpmtst_add_fancybox_data_attr( $img, $id, $size ){
    
                   if ( has_post_thumbnail( $id ) ) {
    
                                  $img = get_the_post_thumbnail( $id, $size );
    
                   }
    
                   if ( WPMST()->atts( 'lightbox' ) ) {
    
                                  $url = wp_get_attachment_url( get_post_thumbnail_id( $id ) );
    
                                  if ( $url ) {
    
                                                 $attr = 'data-fancybox="testimonials"';
    
                                                 $class_array = array( WPMST()->atts( 'lightbox_class' ) );
    
                                                 $classes     = implode( ' ', array_unique( apply_filters( 'wpmtst_thumbnail_link_class', $class_array ) ) );
    
                                                 $img         = sprintf( '<a '.$attr.' class="%s" href="%s">%s</a>',  $classes, esc_url( $url ), $img );
    
                                  }
    
                   }
    
                   return $img;
    
    }
    
    add_filter( 'wpmtst_thumbnail_img', 'wpmtst_add_fancybox_data_attr', 15, 3 );

    If you do not have a child theme, you can add it in your theme’s functions.php file, however, keep in mind that when the theme is updated this code will be removed.

    I also recommend doing a site back-up before making changes to the functions.php file.

    Warmly,

    Beatrice.

    Thread Starter fichter

    (@fichter)

    Thank you very much! That`s all i need

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Customize thumbnail’ is closed to new replies.