What is the WordPress `{$type}_template` filter chain and how can you programmatically override which template file is loaded?

WordPress Fundamental Hard

WordPress Fundamental — Hard

What is the WordPress `{$type}_template` filter chain and how can you programmatically override which template file is loaded?

Key points

  • The template_include filter is specifically designed for overriding template files programmatically.
  • It allows plugins to serve custom templates from their own directory.
  • Using add_action('template_redirect') or template_path filter won't achieve the same result.
  • Directly calling load_template() in a plugin bypasses the hierarchy but doesn't utilize filters like template_include.

Ready to go further?

Related questions