I have searched on this and I only found one reference to the topic anywhere and it was brief and vague but at least one person said repeating the function over and over is best. But, that doesn’t seem right.
Example:
Using WordPress, I’m writing my functions.php file and I have to call get_template_directory_uri() to get the path to my template files.
Usually developers seem to just use that function over and over as many times as needed. But, it was my understanding that this is wasteful and it’s simpler to just call the function once, put it in a global variable, and use the variable throughout the page.
Or, if globals are undesirable it could at least be called only once per function, assigned to a variable, and then the variable gets used 10 times in a row, to enqueue styles and scripts for example.
So, instead of:
[CODE]… get_template_directory_uri() . ‘/path/to/file/1.css’
… get_template_directory_uri() . ‘/path/to/file/2.css’
… get_template_directory_uri() . ‘/path/to/file/3.css’
It would be:
[CODE]$template_directory_uri = get_template_directory_uri();
… $template_directory_uri . ‘/path/to/file/1.css’
… $template_directory_uri . ‘/path/to/file/2.css’
… $template_directory_uri . ‘/path/to/file/3.css’
Doesn’t repeating a variable over and over make more sense that using a function repeatedly? It’s not like it’s changing.
What’s the best practice? Thanks