{"id":2890908,"date":"2012-07-13T04:07:33","date_gmt":"2012-07-13T04:07:33","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/quick-theme-function-question\/"},"modified":"2016-08-20T13:45:11","modified_gmt":"2016-08-20T13:45:11","slug":"quick-theme-function-question","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/quick-theme-function-question\/","title":{"rendered":"Quick Theme \/ Function question"},"content":{"rendered":"<p>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.<\/p>\n<p>I have added the code block below to my function.php file<\/p>\n<pre><code>function determine_thing($post){\n\n\t\tglobal $post;\n\t\tglobal $thingType;\n\t\t$thingType = &quot;&quot;;\n\t\t$id = $post-&gt;ID;\n\t\t$thingType = get_post_meta($id,&#039;thingtype&#039;,true);\n\t\t$category = get_the_category($id); \n\n\t    switch ($category[0]-&gt;slug)\n\t\t{\n\t\t\tcase &quot;thing&quot;:\n\t\t\t$thingType = &quot;a&quot;;\n\t\t\tbreak;\n\n\t\t\tcase &quot;thing2&quot;:\n\t\t\t$thingType = &quot;b&quot;;\n\t\t\tbreak;\n\t\tdefault:\n\t\t\t$thingType = &quot;c&quot;;\n\t\t\tbreak;\n\t\t}\n\nreturn $thingType;\n\n}\nadd_action(&#039;the_thing&#039;, &#039;determine_thing&#039;);<\/code><\/pre>\n<p>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?<\/p>\n<pre><code>global $post;\n$thingType = do_action(&#039;the_thing&#039;, $post);<\/code><\/pre>\n<p>thanks in advance<\/p>\n<p>Ilan<\/p>\n","protected":false},"template":"","class_list":["post-2890908","topic","type-topic","status-closed","hentry","topic-tag-action-hooks","topic-tag-function-php","topic-tag-theme-development"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2890908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/2890908\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=2890908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}