Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I get this error in my theme:

Catchable fatal error: Object of class WP_Error could not be converted to string in /home/winentra/public_html/ on line 186

Line No. 186:

echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');


 elseif ( is_single() ) {
          $cat = get_the_category(); 
              $cat = $cat[0];
          echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
          echo $currentBefore;
          echo $currentAfter;

Any ideas on this please?

share|improve this question

2 Answers 2

If you call get_the_category() without a parameter you have to use it in a loop – after the_post(); was called. Otherwise get_the_category() returns FALSE and get_category_parents() returns a WP_Error object … which is lacking a toString() method and therefore cannot be printed.

So test if you get an object or a string before you try to echo the return value.

share|improve this answer

What @toscho means is that here:

It clearly states that

Return Values


The categories, separated by $separator. WP_Error on failure.

So you can't assume the output will be string and echo it. It can also be a WP_Error object. You need to test it using:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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