WordPress.org

Ready to get started?Download WordPress

Forums

Simple Lightbox
[resolved] Make it work on using 'get_the_content()'? (3 posts)

  1. okiwan
    Member
    Posted 9 months ago #

    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/

  2. okiwan
    Member
    Posted 9 months ago #

    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!

  3. Archetyped
    Member
    Plugin Author

    Posted 9 months ago #

    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.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.