0

I'm trying to change a hardcoded variable value to dynamic, but can't seem to get the concatenation correct...

The hardcoded value is...

$token = "../wp-content/themes/mytheme/styles/test/sidebar";

And I'm trying to replace that with...

$token = ".get_bloginfo('template_directory')."styles/test/sidebar";

But its not working the same as when I hardcode the value.

What am I missing?

Here's the rest of the code (the imagegif function never fires with the dynamically generated variable...

$color = imagecolorallocate($img, $info["red"], $info["green"], $info["blue"]);
    for ($i = $startPixel-1; $i < $endPixel; $i++)
    {
        imagesetpixel($img, $i, 0, $color);
    }

    imagegif($img, $token.'.gif');
}

5 Answers 5

1
$token = get_bloginfo('template_directory') . "styles/test/sidebar";

The . is the concatenation operator, so you wouldn't want the get_bloginfo() function inside of quotes. This assumes the function returns a string that ends in a /

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Fosco, I missed that. Also had to put a "/" in front of "styles".
0
$token = get_bloginfo('template_directory')."styles/test/sidebar";

Is that what you mean? You had the function as a string instead of a function.

Comments

0

From your code:

$token = ".get_bloginfo('template_directory')."styles/test/sidebar";

This line has a a stray quote and period at the beginning. You probably wanted to do:

$token = get_bloginfo('template_directory') . "styles/test/sidebar";

Function calls cannot be within strings, and the concatenation operator (.) must be outside of the string.

Comments

0

Only strings should be wrapped within quotes.

$token = get_bloginfo('template_directory') . "styles/test/sidebar";

Comments

0

Your concatination is a bit off.

Try: $token = get_bloginfo('template_directory') . 'styles/test/sidebar';

2 Comments

"Your concatination is a bit off."... is that not the question ?
Maybe I meant his style of concatenating being a bit weird. But yeah, that was the question I guess ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.