This trick has been very useful for me in many occasions. As you guys know, the page serves by WordPress is generated from the active theme according the template hierarchy. However, there’s a time when you don’t want to follow this rule and serve custom template instead. For instance, like what I did with WooCommerce Newsletter Generator: for the “Newsletter” custom post type to display appropriate HTML email template, I route the newsletter single page to the page defined by the plugin. This thing can be easily done by filtering template_include and return different path for some condition. This is how to do it:

Share Your Thought