admin管理员组文章数量:1426014
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.
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 asked Oct 10, 2012 at 15:41 Nisha_at_BehanceNisha_at_Behance 7032 gold badges7 silver badges14 bronze badges 02 Answers
Reset to default 13I 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');
The problem is that the PHP function include
(roughly speaking) echoes the content and then returns a boolean value.
If you switch the include
for file_get_contents
then your $output
will be a string of the file content rather than the boolean value indicating the success of the inclusion.
Works for me with Wordpress5.2 & PHP7.
本文标签: Shortcode output always showing at top of page
版权声明:本文标题:Shortcode output always showing at top of page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745460042a2659281.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论