I want to show some description of my blog post at home page and a read more link when user will click that link it will redirect to post detail page. I am using the_content('Read More...') function. Now how can i give character limit that how many character i want to display at home page. Please help.

Dani AI

Generated

asked for short text on the homepage and the full post on the single page. correctly pointed to WordPress excerpts and noted listing tools — both are useful directions. Below are practical, theme-friendly options: use the manual Excerpt field as the primary source with a programmatic fallback, or trim by words/characters in the template while keeping links and avoiding broken HTML.

Enable the Excerpt box in Screen Options and write a short summary there. If a manual excerpt is missing, use this fallback in your loop template (index.php / content.php) to trim the content to ~30 words and append a read-more link:

<?php
$manual = get_post_field( 'post_excerpt', get_the_ID() );
if ( $manual ) {
    echo esc_html( $manual ) . ' <a href="' . esc_url( get_permalink() ) . '">Read more</a>';
} else {
    $text = strip_shortcodes( get_the_content() );
    $text = wp_strip_all_tags( $text );
    echo wp_trim_words( $text, 30, '... <a href="' . esc_url( get_permalink() ) . '">Read more</a>' );
}
?>

If you need a true character limit that avoids chopping multi-byte text and keeps basic HTML stripped, use wp_html_excerpt on a cleaned string:

<?php
$clean = wp_strip_all_tags( strip_shortcodes( get_the_content() ) );
$short = wp_html_excerpt( $clean, 160 );
if ( function_exists('mb_strlen') ? mb_strlen( $clean ) > 160 : strlen( $clean ) > 160 ) {
    $short .= '... <a href="' . esc_url( get_permalink() ) . '">Read more</a>';
}
echo $short;
?>

Notes and troubleshooting: inserting the <!--more--> tag in a post controls where the content breaks for themes that output the content before the more tag. If edits don’t show, clear any cache and check which template part the homepage uses (some themes use custom queries or page builders). For best SEO and control, prefer manual excerpts for important posts. If formatting must be preserved inside excerpts, consider a vetted plugin or a more advanced HTML-safe trimming routine.

Recommended Answers

All 2 Replies

Use 'the_excerpt()' function and you need to insert the content in the excerpt field at wordpress back-end.

visit Create post list based on category or with categories, sort list by newest, popular etc, jQuery show/hide effect while listing posts with category.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.