All Courses > Up and Running > Chapters > Make Your Themes Better by Getting to Know get_template_part()

Make Your Themes Better by Getting to Know get_template_part()

Key Takeaways about template parts in WordPress:

"Template parts" are incomplete pieces of WordPress PHP templates, pulled out into their own PHP files. Template files access them with a function called get_template_part().
The primary reason to create a template part in WordPress is to avoid repeating code: if multiple files use several identical lines of code, this code can be pulled into a template part, allowing it to be stored (and modified) in a single place.
get_template_part() can accept two arguments which, together, specify both a target template part file and a fallback file—much as the WordPress template hierarchy falls back to index.php. get_template_part() will also search the child theme (if one exists) for the targeted template part.

In WordPress, get_template_part() is a helpful way to avoid duplication and repetition within a WordPress theme. Use get_template_part() for any t...