Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

rel="lightbox" not working with do_shortcode function WordPress



I have a little problem with a current project and the plugin [[LINK href=""]]WP jQuery Lightbox[[/LINK]]. Like always, when I use the plugin with the gallery shortocde like [gallery link="file"] it works fine inside the content of the post (the plugin adds the rel="lightbox" parameter to all the images of the gallery).

But now, I've found a problem using the gallery shortcode ousite the content. I'm running the gallery this way with the do_shortcode function: echo do_shortcode('[gallery link="file"]');

Looking at the plugin code, I see that the filters which add the rel="lightbox" attribute to a gallery inside the content are:

add_filter('the_content', 'jqlb_autoexpand_rel_wlightbox', 99);
add_filter('the_excerpt', 'jqlb_autoexpand_rel_wlightbox', 99);

This filters are only running on the_content and the_excerpt, so I'm trying to add a filter to the do_shortcode function this way but it's not working fine:
add_filter('do_shortcode', 'jqlb_autoexpand_rel_wlightbox', 99);

Do you know how can I make the do_shortcode function work?

Answers (3)


Oleg Butuzov answers:

have you tried

apply_fitlers('the_content', '[gallery link="file"]');
note - current post_id and post shoue be defined.

Andreu Llos comments:

I don't need to apply the filter into the content, I want to apply it outsite the content with the do_shortcode function!

Oleg Butuzov comments:

do_shortcode - line 144

do_shortcode_tag - line 193

same - line 296
add_filter('the_content', 'do_shortcode', 11); // AFTER wpautop()

happy debuging man...!
shortcodes dosn't have filters. but you can do that with <strong>the_content</strong>

or you can remove or add shortcodes. (repalce it by your custom search..)

related to the gallery you can repalce the content by one more way, but its not intresting to give all answers just for 4 $ =)

Oleg Butuzov comments:

Please minus my P/S/.


Denzel Chia answers:


Use the following str_replace with the do_shortcode function, before echoing out.

$gallery = do_shortcode('[gallery id="123"]');

$process_gallery = str_replace( 'a href' , 'a rel="lightbox" href' , $gallery );

echo $process_gallery;

Hope it helps!


Denzel Chia comments:


Remember to replace with a valid gallery id!
Whereby id is the post id of your gallery.


Andreu Llos comments:

Nice and fast solution. Thank you all!

Denzel Chia comments:

Thanks! Can you please award the price money?


Rashad Aliyev answers:

Open your site in Internet Explorer and see error details if it's have..

Andreu Llos comments:

There is no error. Simply the plugin function is not executed with the filter I've tried for the do_shortcode function.
I need to execute the plugin function in the do_shortcode function in the same way it is executing in the_content function.