Skip to content
A simple WordPress plugin that works like get_template_part but allows you to pass variables.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Get Template Part with Variables

A simple WordPress plugin that works like get_template_part() but allows you to pass variables to the rendered template.

The variables must be passed as an associative array where the keys would be valid variable names.

You should be careful to NOT use any variable names that WordPress includes automatically. The plugin will bring all of those defaults in first, and if the variable you pass to this function would overwrite an existing variable, an exception will be thrown.


$variables = [
    'name' => 'John',
    'class' => 'featuredAuthor',

jpr_get_template_part_with_vars('author', 'info', $variables);

// In author-info.php:
echo "
<div class='$class'>

// Would output:
<div class='featuredAuthor'>
You can’t perform that action at this time.