Archived topic
Showing category only on content-single.php, not content.php
9 replies · Started by Elio Martinez on September 14, 2017
Hi,
I want to show the category of each post in the content-single.php (without the folder icon) and not in the content.php (home, category archives, etc).
It is possible?
Thanks.
Hi there,
So you want to show the current categories attached the post being viewed? Where would you want them to display?
Above the title:
Without the folder icon and with the possibility to change the color of the text.
You could try this:
add_action( 'generate_before_content', 'tu_add_post_categories' );
function tu_add_post_categories() {
if ( is_single() ) {
$category = get_the_category();
echo '<div class="entry-meta">' . $category[0]->cat_name . '</div>';
}
}
I tried that but with that fix the category is showed in every post (without css) in content.php and content-single.php and I only want that in content-single.php, not in home, category sections, etc.
Oops sorry about that - code updated above :)
Hi Tom,
With that code is solved, but the category is showed without any css. I don't want the folder icon, but I still want the same old css for the category word so I think that you have to tweak the code again.
Give it a shot now :)
Thanks :)
No problem :)