Reputation: 261
Wordpress 5.0.3 Shared LAMP Hosting
I'm devloping a plugin that requires a shortcode like this:
function my_shortcode() {
require_once( 'includes/functions.php' );
$my_text = '<pre id="myspecs>'.get_all_stats().'</pre>';
return $my_text;
}
add_shortcode('MyShortCode', 'my_shortcode');
When I insert [MyShortCode] into the page content, the get_all_stats() data are rendered, but pre html formatting rendered after the data, separately. Rendered source looks like this:
<div class="entry-content">
Mywordpressdata-all-in-a-jumble-over-multiple-lines-squashed-together...
<pre id="myspecs">\n\n</pre>
</div>
How can I tell WP to keep the data inside the pre html formatting?
Upvotes: 1
Views: 326
Reputation: 2082
This should fix it,
function my_shortcode() {
ob_start();
require_once( 'includes/functions.php' );
?>
<pre id="myspecs><?php get_all_stats(); ?></pre>
<?php
return ob_get_clean();
}
add_shortcode('MyShortCode', 'my_shortcode');
more info
Upvotes: 1