How can I get a post or page’s title by its ID in WordPress?

 
// Display post title using post ID
echo get_the_title( 5 );

// Display post title and safely escape value
echo esc_html( get_the_title() );

// Using the_title function to automatically echo the title, while you can append or prepend the title using the function as displayed below
the_title( 'Before:', ' - After' )

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

Share This