WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Well, for me the problem, was including during the post content it would not work, but if i did included in the top of the page template model i created, then it would work if i used something like this: VALID FOR PHP 5.3+

$array = array("keywords" => "keywords here", "description" => "desc here");
add_action( 'wp_head', function() use ( $array ) {
    foreach ($array as $key => $value) {
        if ($key == "description") { echo "your meta here"; }
}, 1 );
share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.