I am trying to exclude a category from <?php the_category(', ') ?> inside my loop. I came across the following code on CSS tricks that says would solve the problem. You add this to the functions:

function exclude_post_categories($excl='', $spacer=' '){
   $categories = get_the_category($post->ID);
        $exclude = explode(",", $exclude);
        $thecount = count(get_the_category()) - count($exclude);
        foreach ($categories as $cat) {
            $html = '';
            if(!in_array($cat->cat_ID, $exclude)) {
                $html .= '<a href="' . get_category_link($cat->cat_ID) . '" ';
                $html .= 'title="' . $cat->cat_name . '">' . $cat->cat_name . '</a>';
                    $html .= $spacer;
            echo $html;

And then this <?php exclude_post_categories('1'); ?> to exclude the categories. However when I attempt to use this I get the following errors:

enter image description here

I noticed this solution was up on Stack Exchange as well and I am wondering if I am missing something or is there a more up to date solution that I am missing?

  • 1
    Looks like you copied it into your codebase multiple times, you can't have multiple functions with the same name
    – Tom J Nowell
    Commented Feb 25, 2021 at 19:19
  • @TomJNowell thank you, noticed the error in my functions file after pointing it out. Really appreciate it!
    – Ed Manson
    Commented Feb 26, 2021 at 9:05
  • @TomJNowell sorry I thought this was fixed but when pushed live I get the above errors. If you get a chance to look I'd appreciate any feedback,
    – Ed Manson
    Commented Feb 26, 2021 at 15:53
  • Have you completely rewritten your question? The question I see now is not the question I commented on, it's a whole new question. Your original question asked about a PHP fatal error about redeclaring functions yet all trace of that problem has dissapeared and a new question put in its place. If you have a new question, ask a new question, don't edit it over the top of an existing one.
    – Tom J Nowell
    Commented Feb 26, 2021 at 20:49
  • I have rolled back the edit history so that your question is still the original question. If you want to ask a new question use the Ask Question button or go to wordpress.stackexchange.com/questions/ask
    – Tom J Nowell
    Commented Feb 26, 2021 at 20:57

1 Answer 1


The fatal error occurs because there are multiple functions with the same name. Function names must be unique. Remove the duplicate functions or rename the functions so that they are all unique and the fatal error should go away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.