I'm developing a plugin to wordpress using WordPress Plugin Boilerplate. Therefore, I need to create a shortcode to show up my data in one page for the user.
Is it correct to concatenate the HTML as below?
function custom_shortcode( $atts ) {
// Attributes
$atts = shortcode_atts(
array(
'type' => 'type'
),
$atts
);
//get all entries (page 1 with 999999 entries per page should do it:)
$data = Data::get_entries( $atts['type']);
ob_start();
?>
<div class="row">
<header><h3>Expenses</h3></header>
<p>
<span class="cf-entries-header app-name">Expense Origin</span>
<span class="cf-entries-header page-name">Expense Value</span>
</p>
<?php
foreach ( (array)$data['entries'] as $entry ) {
echo '<p class="cf-entry">’ .
‘<span class="exp-origin">' . $entry['data']['origin'] . '</span>’ .
‘<span class="exp-value">' . $entry['data']['value'] . '</span>’;
};
?>
</div>
<?php
$output = ob_get_clean();
return $output;
};
}
add_shortcode( 'cf_app_entries', 'cf_app_entries' );
ob_*, however, it could be much simpler using.=as such: wpza.net/wordpress-setup/how-to-build-a-wordpress-shortcode - WPZA