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/s1.ssonline.co.in/wp-content/themes/peekaboo/admin/common-functions.php 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?


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.


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:


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.