Code example for removing the author name from metadata on single post pages and blog archive pages when using the Astra theme
Sometimes you may want to hide the author’s name from the metadata on a single post page or in the blog post listing on your WordPress site — especially if you are using the Astra theme. This can be useful for websites where authorship is not relevant or when you want to give your content a more neutral and uniform appearance.
In this article, you’ll learn how to easily remove the author from post metadata
by adding just a few lines of code to your child theme’s functions.php
file.
How Metadata Works in the Astra Theme
The Astra theme provides hooks and filters that allow you to customize the display of metadata (such as date, author, categories, etc.) on post pages and archive listings. We will take advantage of these features to remove the author.
Add Code to functions.php
Open your child theme’s functions.php
file and add the following code:
PHP Code:
add_filter('astra_single_post_meta', 'custom_post_meta');
add_filter('astra_blog_post_meta', 'custom_post_meta');
function custom_post_meta($old_meta) {
$post_meta = astra_get_option('blog-single-meta');
if (!$post_meta) return $old_meta;
$value_to_remove = 'author';
$new_post_meta = array_filter($post_meta, function ($item) use ($value_to_remove) {
return $item !== $value_to_remove;
});
$new_output = astra_get_post_meta($new_post_meta, "/");
if (!$new_output) return $old_meta;
return "<div class='entry-meta'>$new_output</div>";
}
What This Code Does
astra_single_post_meta
— applies the filter to single post pages.astra_blog_post_meta
— applies the filter to archive and blog listing pages.-
astra_get_option('blog-single-meta')
— retrieves the current set of metadata options from the Astra theme settings. array_filter(...)
— removes theauthor
item from the array.astra_get_post_meta(...)
— generates the HTML output for the remaining metadata items.
Useful Tips
-
Use a child theme: Always make changes in your child theme’s
functions.php
file to ensure your customizations are preserved during theme updates. - Clear the cache: After making changes, be sure to clear your site’s cache (if you use a caching plugin like WP Super Cache, LiteSpeed Cache, or WP Rocket) and your browser cache to see the updated output.
Conclusion
Hiding the author is a common customization task for blogs. With Astra’s filters and a few lines of PHP code, you can easily control the display of post metadata and tailor the blog appearance to suit your needs.
27