So I was recently working on a new plugin that involved shortcodes but ran into a bit of a problem when the contents kept getting output at the top of posts/pages before the rest of the content.
Basically this happens because the shortcode is simply returning the data as soon as it’s generated it, not taking note to output it specifically where the user desires. Normally it’s because the content was echoed and not stored and later returned. You can read more about it in this great post but it’s really as simple as that.
However, I was recently faced with this issue and couldn’t figure out why! I was returning the data but it was still being output at the beginning of the post’s content before everything else. I was returning another function (that echoed the content) within my shortcode’s function but it wasn’t helping.
It looked a little bit like this:
DON’T DO THAT!
What you need to do is run the function through an output buffer with
ob_get_clean();, like so:
And it works! For the PHP nerds, you may be interested why we’re using
ob_get_clean(); instead of
ob_clean(); – then check out this discussion.
I decided to put together a small little WordPress plugin today, using the incredible fancyBox jquery lightbox.
It’s called Light, and it’s just that: a Lightbox and a light-weight plugin. No settings or detailed instructions or anything like that. Just install it and it works.
Want to see a demo? Cool. Here you go.
It’s actually pretty flexible, so I wrote a whole lot of documentation for it over on Captain Theme. You can view the documentation for it there.
Regarding the License, I personally don’t care what you do with the plugin but fancyBox is under a Creative Commons License that basically allows you to use it in personal/non-commercial projects for free but you have to pay if it’s for a commercial site (and you should – it’s well worth the money and the developer deserves it!). Read more about the fancyBox License.
It’s also on GitHub! How exciting. Check out the GitHub repository.
Have a question or need help? Leave it below and I’ll try to answer it.
Documentation / Demo
Recently when developing a site powered by Easy Digital Downloads, I wanted one of my products to display differently from the others in the store.
When this problem arises with pages, we can easily create a page template to solve the problem. However, when it comes to creating custom templates for other items such as posts and custom post types, we need a plugin. That’s where the incredible Custom Post Template plugin by Simon Wheatley comes in. By installing the plugin you can easily create templates for your posts, but what about for downloads? Also very easy due to the extensible nature of the Custom Post Template plugin.