Passing variables to get_template_part in WordPress
Use the WordPress locate_template() function within PHP’s include(), instead of get_template_part().
<?php
$var = 'Hello World!';
include(locate_template('file/path/filename.php'));
?>
In file/path/filename.php:
<?php
echo $var;
?>
returns:
Hello World!
Credits: Keith Devon
Written by pimschaaf
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Wordpress
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#