Support » Plugin: Simple Lightbox » Make it work on using 'get_the_content()'?

  • Resolved okiwan

    (@okiwan)


    To make things short: I have a VERY specific template where I have to retrive posts contents (using get_the_content) previously to output it. Unfortunately, Simple Lightbox, while it works like a charm on other situations, is hooking only on the_content so it’s not working for me. Is there any possibility to fix this?

    I have already tried adding a filter manually, but it is not working. Keep investigating alghough…

    Any suggestion/clue will be greatly appreciated 🙂

    Thanks!
    Sergio

    http://wordpress.org/plugins/simple-lightbox/

Viewing 2 replies - 1 through 2 (of 2 total)
  • All right, I think I found a solution. Of course it’s not an elegant one, but at least it works flawlessly on any situation and avoid any kind of coupling (if this is a right term) between my theme and the plugin.

    The problems is that, by using get_the_content(), WordPress does not apply any filters to it. It only does it using the_content(). So, what we are going to do is use it.

    As we know the_content prints on screen but, what happens if we put this onto a temporary buffer? PHP function ob_start() creates an output buffer, which will held the contents without displaying them, and those contacts will be affected by the filters for sure. Finally, we will call ob_get_clen() to retrieve and store them in a variable and clean the buffer. Pretty neat. Here’s all together:

    // Whatever you have to do here...loop, etc.
    
    ob_start();
    the_content();
    $theOutput = ob_get_clean();
    
    // ...whatever you have to do with the output, now with all filters applied (and, on this case, with lightbox working flawlessly

    Cheers!

    Plugin Author Archetyped

    (@archetyped)

    Output buffering will do the trick.

    Alternatively, if you want more control over the content, you can manually apply the filters hooked into the_content (such as SLB):

    $my_content = apply_filters('the_content', get_the_content());
    

    In general though, get_the_content() is primarily useful for when you want the raw/unfiltered content, not just when you don’t want it to be output to the browser. the_content() does additional processing to the content to prepare it for display, so output buffering may be the better option in your case.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Make it work on using 'get_the_content()'?’ is closed to new replies.