WordPress template_include

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Parameters

ParameterExplanation
$templatePasses one parameter to the filter, $template is the current path to the appropriate file for the post type as found in the active child theme or parent theme (if no child theme in place or child theme has lower ranked templates. See wordpress template hierarchy for more details).

Remarks

You must return $template even if not modifying. If this confuses you, look at examples where apply_filter() has been used in code

You should not set up variables here for use later, there are better hooks for this.

A useful program flow for this filter is:

  1. Check $template includes our custom post type name --> template hierarchy!!
  2. if not, search our plugin for suitable files --> Its better to point to specific files rather than searching through folders for files. More efficient. But completely up to the developer.
  3. return the template.


Got any WordPress Question?