if you’re not planning on adding much html there is no need to use ob_start
just return the php:
function wpb_description_shortcode( ){
if (get_post_meta(get_the_ID(), 'song_number', true)) {
return get_post_meta(get_the_ID(), 'song_number', true).'<br/>';
} else {
return;
}
}
// Register shortcode
add_shortcode('my_description_number', 'wpb_description_shortcode');
I’m not sure what this data is, but it would be a good idea to sanitize it too for security.
If you’re planning on adding more fields you could do it like this:
function wpb_description_shortcode( ){
$output="";
if (get_post_meta(get_the_ID(), 'song_number', true)) {
$output .= get_post_meta(get_the_ID(), 'song_number', true).'<br/>';
}
if (get_post_meta(get_the_ID(), 'another_field', true)) {
$output .= get_post_meta(get_the_ID(), 'another_field', true).'<br/>';
}
//random html
$output .= '<h3> cool html </h3>';
if (get_post_meta(get_the_ID(), 'even_another', true)) {
$output .= get_post_meta(get_the_ID(), 'even_another.', true).'<br/>';
}
return $output;
}
// Register shortcode
add_shortcode('my_description_number', 'wpb_description_shortcode');