get_the_title()
is a WordPress function that returns the title of the current post or a specified post. Here’s how you can use it:
- To get the title of the current post:
php
echo get_the_title();
- To get the title of a specific post by post ID:
php
echo get_the_title( $post_id );
Replace $post_id
with the ID of the post you want to get the title of.
- To get the title of a specific post by post object:
php
$post_object = get_post( $post_id );
echo get_the_title( $post_object );
Replace $post_id
with the ID of the post you want to get the title of. In this case, get_post()
function is used to get the post object.
Note: These code examples should be used within the WordPress loop, otherwise the function will not work correctly.