Ok! So you need to pass variables to get_template_part()
in WordPress. Sorry because get_template_part()
is not made to accept variables or arguments. But here is a better way to achieve the same using WordPress’s locate_template()
function within PHP’s include()
.
Passing variables in WordPress to PHP script is done like this:
1 2 3 4 5 | <?php $customvalue1 = 'some value'; $customvalue2 = 'another value'; include(locate_template('your-template-name.php')); ?> |
Notice that we have used template file name along with its extension. In this way all of the variables available in your current script will be available in that template file now too.
So the title of article is quite misleading but the concept is straightforward to pass variables to template files created in WordPress. 🙂
Awesome blog! Is your theme custom made or did you download it from somewhere?
A theme like yours with a few simple adjustements would really make my blog shine.
Please let me know where you got your design. Thanks a lot
Hi,
This is a custom made theme with using Bootstrap 4.
I do not even know how I ended up here, but I thought this post was great. I do not know who you are but certainly you’re going to a famous blogger if you are not already Cheers!
I came to this page by searching google. I have located it quite interesting. thank you for providing this. I will have to visit here again!