get template part parameters

Solutions on MaxInterview for get template part parameters by the best coders in the world

showing results for - "get template part parameters"
Sara
06 Apr 2020
1//NEW CLEAN way (WP 5.5.0 >=) of passing variables to template parts 
2
3$data = array('foo'=>'bar');
4
5//add your variables as a third parameter
6get_template_part( 'template-parts/file', 'name', $data );
7
8//In the template part itself: (IMPORTANT NOTE: the name of the variable has to be args)
9echo $args['foo'];