Using get_template_part() for WordPress 5.5 and above
You can now pass an array within the function arguments of get_template_part()
meaning that you can pass data into the specified template. This can be as simple as a string variable, or as complicated as data can be (array of values, etc.)!
This means that you don’t have to useinclude( locate_template( ‘content-page.php’, false, false ) );
More info can be found within the function reference on the WordPress developer docs.
No more locate_template required
This proves very useful in readability and making it easier for WordPress developers to maintain their code, because what makes the get_template_part()
function different from the PHP core function locate_template()
is that the get_template_part()
function handles this for you.
If you have a look at the code taken from the WordPress 5.5 core file wp-includes/general-template.php
Link to the Github WordPress repo for 5.5 get_template_part()
What you will notice is that it comes handy with hooks —meaning that if needed then the developer has just super-powered your code for you already. There is now less lines to type as well, meaning that overall it will save extra time in getting the code out and maintained, meaning that development costs can be simplified.
What can also be done is to put the data within the get_template_part()
function providing an opportunity to not have to declare it. You can, however, also declare it as an empty one, so that when you get into the specified template part, the data can then be managed through there. The possibilities have just increased!
This provides more context into the variable that it is to be passed within the specified template part, which is the perfect location rather than being called outside the function because that might signify that it is meant to be part of the parent template instead (which isn’t always the case).
More exciting WordPress core updates on the way
This is just one of the many changes found within the WordPress 5.5 update. And that this has been dubbed as the best WordPress update ever. There’s definitely more potential for additional updates in the future, and glad that the updates are getting even more exciting as time goes by!
If it’s available on WordPress — use it to your advantage!