Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I created a shortcode for time.ly's "all in one event calendar app" that makes a paginated list of upcoming events with out all the java script and user options.

I posted about it here. (Its still a work in progress)

As it is now it loads before all the content, I'm guessing because the file returned at the end includes echo's. I'd prefer if it always loaded after the posted content regardless of where it is typed on the page. Is it possible to force a short code to load after page content?

share|improve this question
    
betterwp.net/17-protect-shortcodes-from-wpautop-and-the-likes After some more searching I found the above article. It is similar to how ai1ec handles their shortcodes as well...which means lots of regex. I'm hoping there is a simpler solution? –  juliaallyce Aug 1 '12 at 20:10
    
If you're having problems with wautop and shortcodes, make sure there's not another question about it already, and, if not, ask it separately. –  mrwweb Aug 2 '12 at 15:02
    
My issue is not with wpautop. The article above shows how to find a shortcode in content using regex which could be used to get the short code to load outside of the content. I discovered this is similar to how time.ly makes there could load below post/page content. As I said before I was hoping there might be a simpler solution. In the mean time I've used buffering which I know is not ideal. –  juliaallyce Aug 2 '12 at 21:51
1  
I've never tried this, but what if you put an action on the_content in the shortcode and then just return $content . $something_else? –  mrwweb Aug 2 '12 at 22:05

3 Answers 3

Just run do_shortcode($returned_content) from the plugin, and it will run all shortcode filters on the content.

i.e.

Plugin: MyPlugin.php

function some_func(){
     $data = "[tabs][tab]Tabbed content here[/tab][/tabs]";
     return $data;    
 }

The above function will return the data literally. without the shortcodes being parsed. If you want to parse the shortcodes for display, simply do this:

function some_func(){
     $data = "[tabs][tab]Tabbed content here[/tab][/tabs]";
     return do_shortcode($data);    
 }

This example will parse the shortcodes before return.

share|improve this answer

You could use ajax to fetch the content after the page loads, then insert it into the dom where you want it.

Here are some links that should help:

http://codex.wordpress.org/AJAX

http://codex.wordpress.org/AJAX_in_Plugins

http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/

HTH

share|improve this answer
    
Do you have any examples of this? I'm not very familiar with using ajax :\ –  juliaallyce Aug 1 '12 at 21:10
    
I don't have specific examples atm but here is a tutorial on how to do pagination using ajax to get the next set of posts - wp.tutsplus.com/articles/… –  nvwd Aug 2 '12 at 1:14

The contents of a shortcode should always be returned rather than echoed. You can read more about shortcode output on the Codex.

A while ago, I asked a question about "How to Return Loop Contents" that might prove useful in this situation.

share|improve this answer
    
Your post was the golden one for me. I was baffled because my code did parse in admin but not in frontend, now I know why ;-) I should read first before coding... –  Michael Dibbets Mar 27 at 8:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.