I'm trying to display the author name as a tag. I looked at many forums and it's referring to the get_author methods and the PHP files from the template PHP. However, I do not know what changes to make in the get_author method in order to return his name as a tag for a simple blog post.

I've looked at the following references:

I do not know which files to edit and where to put it as PHP is not my go to language. It would be really helpful if someone can guide me and help me return the author's name as a tag.

It should display something like:

Posted by author name (but it's a tag)

When I do this:

This post was written by <!--?php the_author(); ?-->

It doesn't display the authors name.

Right before my post in dashboard:

<p>The author of the post: <?php the_author(); ?></p>

After doing more research, it says this code must be put in the themes's index.php however, I do not know where in that index.php.


<!-- Display a comma separated list of the Post's Categories. -->
<p class="postmetadata">Posted in <?php the_category(', '); ?><?php the_author(); ?></p>

<?php get_header(); ?>

<div id="middle">

  <div id="container">
    <div id="ipilogue_logo"></div>
    <!-- Display the Time. -->
    <?php the_time('F j, Y'); ?><br/><br/>
    <!-- Start the Loop. -->
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <!-- The following tests if the current post is in category 3. -->
    <!-- If it is, the div box is given the CSS class "post-cat-three". -->
    <!-- Otherwise, the div box will be given the CSS class "post". -->
    <?php if ( in_category('3') ) { ?>
    <div class="post-cat-three">
      <?php } else { ?>
      <div class="post">
      <?php } ?>

        <!-- Display the Title as a link to the Post's permalink. -->
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

        <!-- Display the Time. -->
        <small><?php the_time('F j, Y'); ?></small>

        <!-- Display the Post's Content in a div box. -->
        <div class="entry">
          <?php the_content(); ?>

        <p>The author of the post: <?php the_author(); ?></p>

        <!-- Display a comma separated list of the Post's Categories. -->
        <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
      </div> <!-- closes the first div box -->

      <!-- Stop The Loop (but note the "else:" - see next line). -->
      <?php endwhile; else: ?>

      <!-- The very first "if" tested to see if there were any Posts to -->
      <!-- display.  This "else" part tells what do if there weren't any. -->
      <p>Sorry, no posts matched your criteria.</p>

      <!-- REALLY stop The Loop. -->
      <?php endif; ?>


  <?php get_sidebar(); ?>
  <?php get_footer(); ?>
  • 1
    Use <?php the_author(); ?> Apr 15, 2019 at 17:38
  • It doesn't return the name either. I am assuming the I make that change in WordPress Dashbord --> POST --> EDIT ??
    – ehaha
    Apr 15, 2019 at 17:39
  • @MikeNGarrett please check the edits. Thank you
    – ehaha
    Apr 15, 2019 at 17:55
  • Where are you putting this? What is the file called and where is it located? Apr 15, 2019 at 18:00
  • It says I have to put the code in theme's index.php as I've put it in the description. Where I have no clue and I've also put the link to the reference.
    – ehaha
    Apr 15, 2019 at 18:01

1 Answer 1


<!--?php the_author(); ?--> is an HTML comment. Means it won't fire the PHP inside it.

As you already found out it should be <?php the_author(); ?> when placed in an PHP template file inside a so called The Loop. Which you are already doing right.

Now there's WordPress' Template Hierarchy. Means you need to place that snippet in the one template that's actually rendering the content you are looking at in your browser. Taking the template hierarchy for a Single Post you can see the order WordPress is looking for existing template files in your theme.

A single post will be rendered via

  1. single-{post-type}-{slug}.php
  2. or single-{post-type}.php if 1. not found.
  3. or single.php if 1. and 2. not found.
  4. or singular.php if 1., 2. and 3. not found.
  5. or index.php as last resort.

Look for one of them, test-edit them until you found the right. Finally, there als may be a template-parts subdirectory inside your theme to render specific content. And the template you are looking for may be referenced as template part and you may need to edit just this specific template part in the end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.