Title: Quick Theme / Function question
Last modified: August 20, 2016

---

# Quick Theme / Function question

 *  [iperez_genius](https://wordpress.org/support/users/iperez_genius/)
 * (@iperez_genius)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/quick-theme-function-question/)
 * I am trying to create a global variable that can be access throughout the entire
   theme, ie the header, footer and sidebar, single and page .php files.
 * I have added the code block below to my function.php file
 *     ```
       function determine_thing($post){
   
       		global $post;
       		global $thingType;
       		$thingType = "";
       		$id = $post->ID;
       		$thingType = get_post_meta($id,'thingtype',true);
       		$category = get_the_category($id); 
   
       	    switch ($category[0]->slug)
       		{
       			case "thing":
       			$thingType = "a";
       			break;
   
       			case "thing2":
       			$thingType = "b";
       			break;
       		default:
       			$thingType = "c";
       			break;
       		}
   
       return $thingType;
   
       }
       add_action('the_thing', 'determine_thing');
       ```
   
 * I believe the registration of this function was successful but i am at a loss
   of how to call it? I have tried the code block below and its not working. Also
   will this actually achieve what i want?
 *     ```
       global $post;
       $thingType = do_action('the_thing', $post);
       ```
   
 * thanks in advance
 * Ilan

Viewing 1 replies (of 1 total)

 *  [datdesignguy](https://wordpress.org/support/users/datdesignguy/)
 * (@datdesignguy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/quick-theme-function-question/#post-2891022)
 * Your function doesn’t ACTUALLY require any arguments since you’re already pulling
   in the `$post` variable by setting `global $post` in your function.
 * So I’m wondering if perhaps it would make more sense for you to attach your `
   determine_thing` function to a standard WP action such as `wp` or `wp_head`.
 * Your function doesn’t need to return anything either if you take this approach,
   as you’ve already set the `$thingType` variable to global as well.
 * I hope this gives you some ideas. Be sure and let us know what solves your problem!
 * -greg

Viewing 1 replies (of 1 total)

The topic ‘Quick Theme / Function question’ is closed to new replies.

## Tags

 * [Action hooks](https://wordpress.org/support/topic-tag/action-hooks/)
 * [function.php](https://wordpress.org/support/topic-tag/function-php/)
 * [theme development](https://wordpress.org/support/topic-tag/theme-development/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [datdesignguy](https://wordpress.org/support/users/datdesignguy/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/quick-theme-function-question/#post-2891022)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
