简体   繁体   English

添加我的自定义页面ID,以在Wordpress中动态更改页面标题

[英]Add my custom page id for dynamically page title change in wordpress

I am a new developer. 我是新开发者。 I want to change page title dynamically in WordPress. 我想在WordPress中动态更改页面标题。 I found some code to change the page title search page, tag page, category page, 404 page, etc. Now I want to change page title name my custom product template page. 我找到了一些代码来更改页面标题搜索页面,标签页面,类别页面,404页面等。现在,我想更改页面标题名称作为我的自定义产品模板页面。 My page id=87. 我的页面ID = 87。 I want to add my product page in this code, how can I do that? 我想在此代码中添加产品页面,该怎么做? I want when my product view page opened the page name should be my product name. 我想在我的产品视图页面打开时,页面名称应该是我的产品名称。

 <title>
            <?php 
            if ( is_category() ) {
                echo 'Category Archive for &quot;'; single_cat_title(); echo '&quot; | '; bloginfo( 'name' );

            } elseif ( is_tag() ) {
                echo 'Tag Archive for &quot;'; single_tag_title(); echo '&quot; | '; bloginfo( 'name' );

            } elseif ( is_archive() ) {
                wp_title(''); echo ' Archive | '; bloginfo( 'name' );

            } elseif ( is_search() ) {
                echo '--Search for &quot;'.wp_specialchars($s).'&quot; | '; bloginfo( 'name' );

            } elseif ( is_home() || is_front_page() ) {
                bloginfo( 'name' ); echo ' | '; bloginfo( 'description' );

            }  elseif ( is_404() ) {
                echo 'Error 404 Not Found | '; bloginfo( 'name' );

            } elseif ( is_single() ) {
                wp_title('');

            } else {
                echo wp_title( '-', false, right ); bloginfo( 'name' );
            } 
            ?>
</title>

How to add my page with this conditions? 如何在这种情况下添加我的页面? Thanks 谢谢

You have 2 options, one is with id and one is with post title 您有2个选项,一个带有ID,一个带有帖子标题

is_single(87);
// 87 is id of page
is_single('My Title');
// post_title of page

More info at https://developer.wordpress.org/reference/functions/is_single/ 有关更多信息, 访问https://developer.wordpress.org/reference/functions/is_single/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM