What's the difference between the_excerpt() and the_content() functions in WordPress?

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Annie_P
    Member
    • Aug 2022
    • 98

    What's the difference between the_excerpt() and the_content() functions in WordPress?

    Hello everyone,

    I'm hoping to gain a clearer understanding of the distinctions between the_excerpt() and the_content() functions in WordPress. If anyone can provide insights or explanations on this matter, your help would be greatly valued.
  • Clay Page
    Member
    • Sep 2022
    • 89

    #2


    In the WordPress ecosystem, the_excerpt() and the_content() are fundamental functions to present content from posts or pages. However, it's important to understand that these functions have separate roles and distinct attributes:


    1. the_excerpt()
    • In WordPress, an excerpt serves as a summary of a longer article. It's frequently utilized as a stand-in on blog index and archive pages, eliminating the need to present the complete content of each post.
    • Invoking the_excerpt() within your WordPress theme template files (such as single.php or archive.php) outputs an excerpt of the post's content.
    • The page will display the chosen excerpt if you have entered one, or if an optional excerpt is not provided, it will show the first 120 words of the post.
    • To adjust the length of the excerpt, you can navigate to the WordPress dashboard, go to "Settings" > "Reading," and make changes to the "Excerpt" option.


    Example:

    <div class="post">
    <h2><?php the_title(); ?></h2>
    <div class="excerpt">
    <?php the_excerpt(); ?>
    </div>
    </div>


    Manually Change the Length of Excerpts
    • You can use excerpt_length in your child theme’s functions.php file.

    function custom_excerpt_length( $length ) {
    return 20;
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );



    2. the_content()
    • This function displays the entire content of a post or page.
    • When you utilize the_content() within your theme template files, it outputs the entire content of the post or page, encompassing all text, images, and other elements.
    • The default behavior of the_content() is to showcase the complete post content. Yet, you can personalize its presentation by applying filters or crafting custom template tags to adjust how the content appears.
    • To showcase only a portion of the post content, the common approach is to utilize WordPress's built-in functions or custom code to extract and display a designated section or confine the content's length.
    Example:

    <div class="post">
    <h2><?php the_title(); ?></h2>
    <div class="content">
    <?php the_content(); ?>
    </div>
    </div>

    Comment

    Working...
    X