简体   繁体   中英

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. 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. My page 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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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