Aj Khandal
This is very common requirement while we are creating template in WordPress. To get title on template pages there are 2 ways.
get_the_title ( int|WP_Post $post ) – We can pass the post id in the parentheses to get the particular post title by default it is $post.
the_title( string $before = ”, string $after = ”, bool $echo = true ) – Display or retrieve the current post title with optional markup.
Example –
<?php echo get_the_title( $post_id ); ?>
<?php the_title() ?>
The two are not 100% identical, though they are close and give same results.