Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have the following front-page template made:

enter image description here

In place of those large Lorem Ipsum blocks, I need to show an "excerpt" from a specific page to fill that box (a certain # of characters).

So my question is: how do I get a pages content in String format so that I can echo it out and trim down to a certain # of characters?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

// would echo post 7's content up until the <!--more--> tag
$post_7 = get_post(7); 
$excerpt = $post_7->post_excerpt;
echo $excerpt

// would get post 12's entire content after which you
// can manipulate it with your own trimming preferences
$post_12 = get_post(12); 
$trim_me = $post_12->post_content;
my_trim_function( $trim_me );

share|improve this answer

If you're in the loop do this:

$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
    // Some string manipulation performed
echo $my_excerpt; // Outputs the processed value to the page

Or if you have an ID, get the post then sue the post_excerpt member var


$post = get_post( $post_id );
echo $post->post_excerpt;
share|improve this answer

you can use this code it is work fine change page_id=19 with your page number:

<?php $the_query = new WP_Query( 'page_id=19' ); ?>

<?php while ($the_query -> have_posts()) : $the_query -> the_post();  ?>

                       <?php the_excerpt(); ?>

     <?php endwhile;?>
share|improve this answer
Wellcome to this site. It seems that thisis your first answer. A explanation of why and how your answer solves the problem is always good. –  cybmeta Dec 27 '14 at 17:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.