Archived topic
How to Display Categories Below Post Title
5 replies · Started by Vish on March 15, 2018
Currently the categories are displayed at the end of the post. I want to display them below the title as below:
Example:
GeneratePress is the best WordPress Theme Right Now (Title)
Category 1, Category 2, Category 3
March 16, 2018 by Vishnu
The categories thing in the second line above is what I'm looking for. And I want this to happen only in single posts page. Not in Blog pages or normal pages.
Also, please let me know where should I add what codes to achieve this.
Hi there,
Try this PHP snippet:
add_action( 'generate_after_entry_title', 'lh_add_cat_below_title' );
function lh_add_cat_below_title() {
if (is_single() ) {
$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generatepress' ) );
$categories_list = sprintf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
_x( 'Categories', 'Used before category names.', 'generatepress' ),
$categories_list
);
}
?>
<div class="entry-meta">
<?php echo $categories_list; ?>
</div>
<?php
}
Adding PHP: https://docs.generatepress.com/article/adding-php/
Hi.
The code is working fine, thank you. Is it possible to only display the parent category?
There is actually am easier solution now.
Can you open a new topic for your question?
Thanks :)
Done :)
Thanks :)