I tried

add_filter( 'page_template', 'single_page_template' );

function single_page_template( $template )
  {
      if ( is_singular( 'dwqa-question' ) ) {

          $template =  get_stylesheet_directory() . "https://wordpress.stackexchange.com/" . page-question.php;
      }
      return $template;
  }

now, if I will out put echo get_page_template(); I am getting

/var/www/html/my-site/wp-content/themes/theme-child/page-question.php

but modifying the page-question.php file not effecting the output ,adding some text to this template like

get_header(); ?>zzzzzzzzz

not getting out put. page.php is assign to single question page using template_include hook is this because of that , but if yes echoing get_page_template() should also give page.php tempalte path as output .

Just modified page.php like

get_header(); ?>aaaa

and aaaa is appearing on page .

How I should override it ?? please let me know if I should provide any other detail ?

4 Answers
4

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 had this issue and it was driving me crazy, until I found the filter on the WordPress Codex: https://codex.wordpress.org/Plugin_API/Filter_Reference/single_template

Leave a Reply

Your email address will not be published. Required fields are marked *