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.

For some reason, my posts content (the content placed outside of the shortcodes I have set up) is only displaying below all the shortcodes, no matter where I place content in the post.

For example, I could set up a post like this:

[boxes cat="Features"]

test content here

[boxes cat="Reviews"]

And the test content will display below the Features AND the Reviews. Why would it do that? Some of my shortcodes use the php include. Here's an example of one of my shortcodes:

function free_ms_cms( $atts, $content = null ) {
   $free_ms = TEMPLATEPATH . '/get-free-ms.php';
   include($free_ms);
}
add_shortcode( 'free-ms', 'free_ms_cms' );

Anyone able to help? Thanks!

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Are your shortcodes setup correctly? This usually means that your shortcode handling is echoing the shortcode content instead of returning it as a string.

For your case, while you are including a file in your shortcode, I doubt that you have the file setup to return the output instead of echo'ing it.

Try this instead:

function free_ms_cms( $atts, $content = null ) {
   $free_ms = TEMPLATEPATH . '/get-free-ms.php';
   ob_start(); //start an output buffer to capture any output
   include($free_ms);
   return ob_get_clean(); //return the current buffer and clear it
}
add_shortcode( 'free-ms', 'free_ms_cms' );
share|improve this answer
    
My shortcodes are using include, I updated my question with one of my shortcodes. I'm not sure if it returns or echoes with include. If you could check it out and update your answer I would greatly appreciate it. Thanks! –  Jared Feb 18 '11 at 3:34
    
I know what you mean now, I've solved my own question with your help. :) –  Jared Feb 18 '11 at 4:04
    
@Jared: post the solution as an answer for future lurking guests. –  Bainternet Feb 18 '11 at 7:49
    
@Jared, I've updated the answer to include code for your particular instance. –  prettyboymp Feb 18 '11 at 13:14
add comment

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.