WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my shortcode output won't appear where I put it, but rather at the top of the content (top of the post/page content).

And here is my code

function service_shortcode_index() {
global $content;
$output = include ( TEMPLATEPATH . '/service.php' );
return $output;
}

add_shortcode('service_mid', 'service_shortcode_index');

there are some regular HTML lists with widget in "service.php"

The content displays correctly, just in the wrong position.

share|improve this question
up vote 4 down vote accepted

I think your problem is with the $output = include .... statement. include() returns true or false based whether it was successful - not the content of the file being included. Use output buffering to get the content.

function service_shortcode_index() {
    global $content;
    ob_start();
    include ( TEMPLATEPATH . '/service.php' );
    $output = ob_get_clean();
    return $output;
}

add_shortcode('service_mid', 'service_shortcode_index');
share|improve this answer
    
Thanks @joseph its great.... – Nisha_at_Behance Oct 10 '12 at 16:06
    
the exception to this is if the included file returns its output, for example if service.php contained just return 'something';, 'something' would get assigned to $output rather than true/false. – Milo Oct 10 '12 at 16:22
    
Thanks for letting me know, @Milo! – Joseph Leedy Oct 10 '12 at 17:09

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.