Adding the_category into the_excerpt

I’d like to begin the_excerpt with the_category on my blog’s homepage. I’ve read through the codex but haven’t found a solution. So, If my Post category is “movies” and “the_excerpt” outputs: “Paul Rudd, Emile Hirsch find sublime, subtle comedy in the … Read More”, I’d like it to instead output “MOVIES | Paul Rudd, Emile Hirsch find sublime, subtle comedy in the … Read More”

Thanks in advance for the help.

Related posts

Leave a Reply

1 comment

  1. the_excerpt() is actually just a call to the filter with the same name, which passes get_the_excerpt()

    function the_excerpt() {
        echo apply_filters('the_excerpt', get_the_excerpt());
    }
    

    In your functions.php file or a plugin, add something like:

    add_filter('the_excerpt','my_add_category',10,1);
    function my_add_category($excerpt) {
        $excerpt = the_category().' | '.$excerpt;
        return $excerpt;
    }
    

    That’s untested, but let me know if it doesn’t work and I’ll load up a local environment and get you something else.