Overriding page template using page_template filter

From your question, it seems you’re trying to override the single template of a custom post type. If so, the filter you want to use is single_template and not page_template: function single_page_template($single_template) { global $post; if ($post->post_type == ‘dwqa-question’) { $single_template = get_stylesheet_directory() . ‘/page-question.php’; } return $single_template; } add_filter( ‘single_template’, ‘single_page_template’ ); I once … Read more

Loading custom page template via plugin

To add custom template in page attributes template section you have to first add your template to dropdown and load it in template_include hook when current page has selected it as current template. /** * Add “Custom” template to page attirbute template section. */ function wpse_288589_add_template_to_select( $post_templates, $wp_theme, $post, $post_type ) { // Add custom … Read more

Password protected posts redirects

TL;TR? Spoiler alert – hover over the next blockquote to expose it. Building an archive that is easily filterable by the currently entered password is nothing that is easy and surely not elegant buildable. The solution involves a secondary query and a small plugin, but it works. All errors and wrong paths are shown as … Read more