the_title

Home » Functions » the_title

One of the most commonly used WordPress functions, the_title(), is used to display the title of a post or a page on a WordPress website. It is a simple and straightforward function that outputs the post or page title in the WordPress loop.

The function takes no arguments, so it is very easy to use. It simply returns the post or page title, which can then be styled with CSS or manipulated in other ways using PHP.

Here’s an example of how to use the_title() in a WordPress loop:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
<?php endwhile; else : ?>
    <p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

In this example, we are using the_title() to display the title of each post in a WordPress loop. We have wrapped the function in an H2 HTML tag to style the title and have also used the_content() function to display the post content.

Overall, the_title() is a simple and useful WordPress function that is used throughout WordPress themes to display post and page titles.

Learn More on WordPress.org

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