This morning I needed to pass a variable to a file that I was including using the WordPress get_template_part function.
I was fiddling around with global variables when I thought there must be a better way. There is.
Locate and include
You can use the WordPress locate_template function within PHP’s include(). It’s done like this:
[code]include(locate_template(‘your-template-name.php’));[/code]
All of the variables available in your current script will be available in that template file now too.
Leave a Reply