Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working on a plugin that adds scripting to the head using


I have to pass a variable to the function to get my desired result. To test this I'm simple "echoing" out the variable to be sure it's passing.

I'm calling the function within a page template. The variable is echoed in the body but not the head:

function add_brand_style($newItem){
    global $newItem;
    echo 'item:'.$newItem;

the head i get "item:' and in the body I get something like "item:dog".

share|improve this question
You are off ot a bad start by adding scripts using wp_head. You should enqueue scripts properly: codex tut –  vancoder Apr 11 '13 at 18:07
Not to mention wp_head shouldn't take in parameters per the codex. –  dcp3450 Apr 11 '13 at 18:14
Possibly you should also look into localizing scripts: codex –  vancoder Apr 11 '13 at 18:17
Have you read Passing a parameter to filter and action functions? –  toscho Apr 11 '13 at 19:49
I think you should give more details on what you're trying to achieve. Where does $newItem coming from? Different enqueueing techniques are possible with conditional tags. The issue is not "why does the hook not accept external parameters", but "how can this be overcome in my specific use case". toschos' link is priceless, favorited! –  brasofilo Apr 11 '13 at 21:07

Your Answer


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

Browse other questions tagged or ask your own question.