'Create shortcode for current post author meta

I have a custom meta field for post author named phone am trying to create a shortcode to display the phone number on the author's post. I have the following, but it's not working.

/*Author Phone Meta*/
function author_phone_sc() {
      return get_the_author_meta( 'phone', FALSE );
}
   add_shortcode("author_phone", "author_phone_sc"); 


Solution 1:[1]

You can try something like the below:

<?php 
function author_phone_sc(){
    ob_start();

    // Get the author ID Outside loop.
    global $post;
    $author_id = $post->post_author;

    //  Get the author ID inside a loop.
    $author_id = get_the_author_meta( 'ID' );
    
    get_the_author_meta( 'phone', $author_id );

    $output = ob_get_contents();
    ob_end_clean();
    return $output;
    
}
add_shortcode( 'author_phone', 'author_phone_sc' );
?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Krupal Panchal