最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Is_Page doesnt detect my page

programmeradmin1浏览0评论

I want to call Servicedeneme.php which is in main folder of theme, in mysite/faq/

It's title is FAQ so I write code for two form which are faq and FAQ.However, it doesnt work.

I write below code to function.php

  if (is_page( 'faq' ) or is_page( 'FAQ' )) {
        get_template_part( 'Servicedeneme' );
    }

Also when I write below code, wp will error:

function show_archieve_styles(){
    if (is_page( 'faq' ) or is_page( 'FAQ' )) {
        get_template_part( 'Servicedeneme' );
    }
}
add_action('wp', 'show_archieve_style');

It says there is no function in error.

So, whats the problem?

I want to call Servicedeneme.php which is in main folder of theme, in mysite/faq/

It's title is FAQ so I write code for two form which are faq and FAQ.However, it doesnt work.

I write below code to function.php

  if (is_page( 'faq' ) or is_page( 'FAQ' )) {
        get_template_part( 'Servicedeneme' );
    }

Also when I write below code, wp will error:

function show_archieve_styles(){
    if (is_page( 'faq' ) or is_page( 'FAQ' )) {
        get_template_part( 'Servicedeneme' );
    }
}
add_action('wp', 'show_archieve_style');

It says there is no function in error.

So, whats the problem?

Share Improve this question asked May 4, 2020 at 3:20 ahmet kayaahmet kaya 331 silver badge9 bronze badges 2
  • If you want to apply a custom template to a specific page name, just name the file page-faq.php. – Jacob Peattie Commented May 4, 2020 at 3:25
  • @JacobPeattie I tried page-faq.php and page-FAQ.php after your comment, but they dont work, why? – ahmet kaya Commented May 4, 2020 at 3:38
Add a comment  | 

1 Answer 1

Reset to default 0

Are you wanting to replace the template file for the entire page or include a certain feature? As @JacobPeattie mentioned in the comments you may want to check out template hierarchy for replacing the whole template.

The get_template_part() function can be used to include a template part into another file. I think that's your use case here. The problem appears to be where you are trying to add the template. I think you'll want to add the following to page.php as that is the default template for pages. I find that the Query Monitor plugin has a useful feature of displaying which template is being used.

 // add to page.php where you want your forms.
 if ( is_page( 'faq' ) || is_page( 'FAQ' ) ) {
        get_template_part( 'Servicedeneme' );
    }
发布评论

评论列表(0)

  1. 暂无评论