logo

$4
rel="lightbox" not working with do_shortcode function

Hi!

I have a little problem with a current project and the plugin WP jQuery Lightbox. 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?

Andreu Llos | 03/16/11 at 7:56am | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    03/16/11
    7:59am
    Rashad Aliyev says:

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

    • 03/16/11 8:21am

      Andreu Llos says:

      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.

  • avatar
    Last edited:
    03/16/11
    10:50am
    Oleg Butuzov says:

    have you tried

    apply_fitlers('the_content', '[gallery link="file"]');

    note - current post_id and post shoue be defined.

    • 03/16/11 8:19am

      Andreu Llos says:

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

    • 03/16/11 8:28am

      Oleg Butuzov says:

      do_shortcode - line 144
      wp-includes/shortcodes.php


      do_shortcode_tag - line 193
      wp-includes/shortcodes.php

      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 the_content

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

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

    • 03/16/11 8:30am

      Oleg Butuzov says:

      Please minus my P/S/.

  • avatar
    Last edited:
    03/16/11
    10:50am
    Denzel Chia says:

    Hi,

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


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

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

    echo $process_gallery;
    ?>


    Hope it helps!

    Thanks.
    Denzel

    • 03/16/11 8:34am

      Denzel Chia says:

      Hi,

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

      Thanks.

    • 03/16/11 10:46am

      Andreu Llos says:

      Nice and fast solution. Thank you all!

    • 03/16/11 10:49am

      Denzel Chia says:

      Thanks! Can you please award the price money?

This question has expired.





Current status of this question: Completed