calling a custom field value inside functions.php


I am creating a function, for a shortcode that I will use directly in the post content (using [my_description_number] shortcode), and it works, but I do not manage to call (echo or print) a custom field value.

this will not print the custom field value, maybe you know how to make it work? just to print the value of custom field song_number when the shortcode will be called

many thanks

function wpb_description_shortcode( $atts ) : string {
  <?php if (get_post_meta(get_the_ID(), 'song_number', true)) { ?> 
  <?php echo get_post_meta($post->ID, 'song_number', true); ?><br/>
  <?php } else { ?>   <?php } ?> 

    return ob_get_clean();
// Register shortcode
add_shortcode('my_description_number', 'wpb_description_shortcode');```

vyperlook 1 year 2022-02-05T18:06:34-05:00 0 Answers 0 views 0

Leave an answer