Title: Cannot access color variable
Last modified: August 30, 2016

---

# Cannot access color variable

 *  Resolved [sebisan](https://wordpress.org/support/users/sebisan/)
 * (@sebisan)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/cannot-access-color-variable/)
 * Hi! How are you?
    Sorry if the question is too stupid, I’m rather new at WP. 
   I can’t find any documentation as to how to retrieve the color variable inside
   the category php.
 * Could you please give me a hand?
 * [https://wordpress.org/plugins/wp-term-colors/](https://wordpress.org/plugins/wp-term-colors/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Pete](https://wordpress.org/support/users/perthmetro/)
 * (@perthmetro)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/cannot-access-color-variable/#post-6893502)
 * Same here, sadly it looks like there’s no examples for newbies or this plugin
   isn’t supported. Pity 🙁
 *  [vitorhugojapa](https://wordpress.org/support/users/vitorhugojapa/)
 * (@vitorhugojapa)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-access-color-variable/#post-8416750)
 * Hi! You can use the following code (obtained in [https://developer.wordpress.org/reference/functions/get_term_meta/](https://developer.wordpress.org/reference/functions/get_term_meta/))
 *     ```
       <?php
       //TO USE IN SINGLE LOOP (single.php)
       //Get the category from the current post in the loop
       $category = get_the_category();
   
       //get_term_meta documentation https://developer.wordpress.org/reference/functions/get_term_meta/
       $color = get_term_meta($category[0]->cat_ID, 'color', true);
   
       //Check if it has a color
       if($color){
         echo '<h1 style="color:', $color , '">Category Color</h1>';
       }
       //
       //
       //
       //TO USE IN CATEGORY LOOP (category.php)
       //Get the category used in the loop
       $category = get_category( get_query_var( 'cat' ) );
   
       //get_term_meta documentation https://developer.wordpress.org/reference/functions/get_term_meta/
       $color = get_term_meta($category->cat_ID, 'color', true);
   
       //Check if it has a color
       if($color){
         echo '<h1 style="color:', $color , '">Category Color</h1>';
       }
       ?>
       ```
   
    -  This reply was modified 9 years, 7 months ago by [vitorhugojapa](https://wordpress.org/support/users/vitorhugojapa/).

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Cannot access color variable’ is closed to new replies.

 * ![](https://ps.w.org/wp-term-colors/assets/icon-256x256.png?rev=1267652)
 * [WP Term Colors](https://wordpress.org/plugins/wp-term-colors/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-term-colors/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-term-colors/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-term-colors/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-term-colors/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-term-colors/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 2 replies
 * 3 participants
 * Last reply from: [vitorhugojapa](https://wordpress.org/support/users/vitorhugojapa/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/cannot-access-color-variable/#post-8416750)
 * Status: resolved