4v2u7a
Last Updated: February 25, 2016
·
5.228K
· pimschaaf

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