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.

2 Answers
2

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');

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *