Last active
November 22, 2019 19:46
-
-
Save interactiveRob/5f3dc2d945b4e9c281117ba4413c2b81 to your computer and use it in GitHub Desktop.
Pass variables to get_template_part() as arguments in Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function rk_get_template_part($template_slug, $args = [], $var_store = false) { | |
| $props = $args; | |
| $template_slug = $template_slug . '.php'; | |
| ob_start(); | |
| include( locate_template($template_slug) ); | |
| $template_output = ob_get_clean(); | |
| if(!$var_store): | |
| echo $template_output; | |
| endif; | |
| return $template_output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment