Jump to content

Recommended Posts

I'm trying to implement the lightbox plugin called Colorbox into my Wordpress theme and I'm having problems with it.

 

You can see a demonstration on this article here.

 

When you click on the images inside the article, then they'll open fine in the lightbox, but when you click on the social media buttons at the bottom (which are images too), then they will open up in the lightbox as well. On top of it when you click on the links inside Internet Explorer they will open up in the lightbox as well, which other browsers don't do.

 

I already came up with a solution for this problem, but I simply don't know the right syntax and would appreciate if somebody could help me with the syntax.

 

The solution is to simply append a class to the anchor tag (only the ones which are wrapped around an image), and then execute colorbox based on that anchor tag.

 

For example (this is just a rough outline)

 

jQuery('.post_content a img').appendTo('a').class('imageLink');

 

And then execute Colorbox:

 

jQuery('.imageLink').colorbox();

 

This will ensure that only the anchor tags wrapped around an image will get a class appended it, and it will ensure that only those will open inside the lightbox.

 

My question is: what would be the correct syntax to achieve this?

 

I hope to hear some suggestions.

 

Thanks.

I came this close:

 

if (jQuery('.post_content img:has(a)')) {
	jQuery('a').addClass('imageLink');
	} 

jQuery('.imageLink').click(function() {
jQuery(this).colorbox();
});

 

Unfortunately it doesn't work and it will still open the normal hyper links in the lightbox.

This is how I finally solved it:

 

jQuery('.post_content img').parent().addClass('imageLink');

jQuery('.imageLink').colorbox();

 

Write less code, do more.

 

I guess I was just over thinking it again, when it was all so easy.

 

Everything is now working as expected.

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.