Using same variable names in files added with get_template_part()

Say I have a file named content-header.php and content-body.php.

In content-header.php I have this variable:

$some_var = ‘apples’;

and in content-body.php I have a variable with the same name but different value:

$some_var = ‘bananas’;

In another file I use:

get_template_part(‘content’, ‘header’);
get_template_part(‘content’, ‘body’);

Would $some_var be limited to its own file or overwrite the other? Is it ok to use same variable names in files added through get_template_part()?

Would I have to use unique variable names?

Read more here:: Using same variable names in files added with get_template_part()

Leave a Reply

Your email address will not be published. Required fields are marked *