How to apply the Lightbox effect to the single post featured image in the Customizr(-Pro) theme

Note :This snippet works only with the Classical style option. The Classical style option can be enabled in Appearance > Customize > Advanced > Theme Style. More about the theme style option here

As you surely know you can display the featured image in single post contexts, with the option located at
Appearance -> Customize -> Content: home, posts, ... -> Single posts
Once enabled Customizr(-Pro) will show either the featured image (also called ‘post thumbnail’) or the first post attachment, if the post thumbnail is not set.
If you enabled the ‘Lightbox effect on images’ option ( Appearance -> Customize -> Global settings -> Image settings ) you might have noticed that it doesn’t apply
to the aforementioned featured image, for the following reasons (both conditions must be satisfied):

  1. that option applies to the images inside the content
  2. that option applies to the images which are linked to the media file

None of them is satisfied because:

  1. the featured image is shown before the content
  2. the featured image is linked to the post itself and not to the media file

With the following snippet you will be able to apply the lightbox effect on the featured image shown in single post contexts.

It will be applied only to those images which are actually the post thumbnail, as there is no sense to apply it also to the the ones which are the first post attachment, otherwise you’ll see the image twice in the fancybox (lightbox) gallery.

That’s all folks!!

Where to copy/paste this code?
Add it to your child-theme functions.php.
Everything you need to know about creating a child theme with Customizr here.

Related Snippets you may also like

We can help you to implement this snippet

Coding is our job and we know WordPress inside and out. We can help you to customize your website with small chunks of code snippets like this one.

Send us your request and we'll get back to you quickly.

2 thoughts on “How to apply the Lightbox effect to the single post featured image in the Customizr(-Pro) theme

Comments are closed.