How To Rearrange Astra Post Elements

A reader asked how to completely rearrange the post elements in WordPress Astra.

They wanted to order it as:

  • Date
  • Post title
  • Author
  • Post content
  • Categories
  • Tags

They also wanted the same ordering on both the single posts and in the category pages.

Regardless of whether you want to order your layout in this exact order, there will be some useful information to help you customize your order.

Display the date above the post title

To get the date above the title I used the code:

add_action( 'astra_single_post_title_before', 'date_before_title' );
add_action( 'astra_archive_post_title_before', 'date_before_title' );

function date_before_title() {
  $date = astra_post_date();
  echo "<div class='entry-meta'>$date</div>";
}

This connects the display of the date into the relevant post_title_before sections.

Display the categories and tags below the content

To display the categories and tags at the bottom I used this code:

add_action( 'astra_entry_content_after', 'category_tag_after_post' );

function category_tag_after_post() {
  if ( !is_single() AND !is_archive() AND !is_home() ) {
    return false;
  }

  $categories = astra_post_categories();
  $tags = astra_post_tags();
  echo "<div class='entry-meta'>$categories / $tags</div>";
}

To see a full description of this code and what it does, have a look at the tutorial on how to display WordPress categories below the content in Astra.

Finally, I hid the date, categories and tags from their default positions, using the Customizer. You can see a full explanation under customizing the Astra post meta.

The end result looked like this:

Ways you could further customize this include putting the category or author above the title, changing the text or HTML wrapping around the code, or doing a different display for the single posts or the category pages.

Mike Haydon

Thanks for checking out my WordPress and coding tutorials. If you've found these tutorials useful, why not consider supporting my work?

Buy me a coffee

Leave a Comment