简体   繁体   English

如何在作者页面上显示作者 ID

[英]How can I display author id on the author page

I'm trying to display the author id on the author page by using a shortcode I created but it's currently not working because the shortcode is only outputting the administrator id.我正在尝试使用我创建的简码在作者页面上显示作者 ID,但它目前不起作用,因为简码仅输出管理员 ID。 This is what I'm returning in the shortcode:这就是我在简码中返回的内容:

return get_the_author_meta('ID'); 

Working code:工作代码:

function author_id_shortcode(){
    ob_start();
    
    // We get the author ID outside loop.
    global $post;
    $author_id = $post->post_author;
    
    //  Now get the author ID inside loop.
    $author_id = get_the_author_meta( 'ID' );
    
    $output = get_the_author_meta( 'ID', $author_id );

    ob_end_clean();
    return $output;
    
}
add_shortcode( 'author_id', 'author_id_shortcode' );

call the shortcode with [author_id]使用 [author_id] 调用简码

Please try the below code on author.php请在 author.php 上尝试以下代码

if (is_author()){
    $author = get_queried_object();
    $author_id = $author->ID;
    echo $author_id;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM