how to add title to wordpress php

Sure.

You can add a title to a WordPress page by using the following PHP code:

<?php
/*
Template Name: My Custom Page
*/
get_header(); ?>

    <div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

            <?php while ( have_posts() ) : the_post(); ?>

                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <header class="entry-header">
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    </header><!-- .entry-header -->

                    <div class="entry-content">
                        <?php the_content(); ?>
                    </div><!-- .entry-content -->
                </article><!-- #post-## -->

            <?php endwhile; ?>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php get_footer(); ?>

Explanation:

  1. The Template Name: My Custom Page part indicates that this is a custom template for a specific page.

  2. get_header() brings in the header template for the page.

  3. The <h1 class="entry-title"><?php the_title(); ?></h1> code displays the page's title using an H1 tag.

  4. the_content() outputs the content of the page.

  5. get_footer() includes the footer template for the page.

This code will ensure that the title is properly displayed on your WordPress page.