get_the_title

Home » Functions » get_the_title

Function Name: get_the_title

If you’re working with WordPress and need to retrieve the title of a post or a page, get_the_title() is the function you need. This function retrieves the title of the current post or a specified post ID.

The get_the_title() function returns the title of the post as a string, which means that you can use it to display the title in your WordPress theme, or to store the title in a variable for further use.

Here’s an example of how you can use get_the_title() in your WordPress code:

<h1><?php echo get_the_title(); ?></h1>

In this example, the function is used to display the title of the current post in an h1 tag.

You can also use get_the_title() to retrieve the title of a specific post by passing the post ID as a parameter. Here’s an example:

$post_id = 123;
$title = get_the_title($post_id);

In this example, the function retrieves the title of the post with ID 123, and stores it in a variable named $title.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.