the_author() str_replace error

If you want to display the author’s name outside the loop, you must use the following code snippet.

First answer: Your definite answer

The code below first takes the ID of the author of the post. Then it displays the author name using the ID

    global $post;
    $get_AuthorId = $post->post_author;
    $getUser_name = get_userdata($get_AuthorId);
    echo $post_author = $getUser_name->user_login;   //  This returns the name of the author of the article

An example of your code will be this

    <div class="left d-flex flex-row gap-3 align-items-center">
        <span class="fw-600"><?php echo get_the_date('F j, Y'); ?></span>
        <span class="dot"></span>
        <span class="fw-600"><?php echo $post_author; ?></span>
    </div>

The second answer: using while

If you want to display the author’s name in while, use the following code
See the code below:

<?php
while (have_posts()) : the_post();
    ?>
    <div class="left d-flex flex-row gap-3 align-items-center">
        <span class="fw-600"><?php echo get_the_date('F j, Y'); ?></span>
        <span class="dot"></span>
        <span class="fw-600"><?php echo the_author(); ?></span>
    </div>
    <?php the_content();  
endwhile;
?>

Pay attention that you must use this code in the single.php page of your wp theme template.

See in the image below, when we use while, it displays the author name

enter image description here

If you have any problem, please leave a comment.