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.

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
add comment

1 Answer 1

up vote 2 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 Oct 10 '12 at 17:09
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.