WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 7 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

Here you go !

$my_id = 5369;
$post_id_5369 = get_post($my_id);
$content = $post_id_5369->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
share|improve this answer
Please, explain what the code does and how it answers the question. Some users may not understand the code without a little explanation. – cybmeta Nov 16 '15 at 8:16
I really like the way you added the_content filter. +1 for that. – Mohammad Mursaleen May 4 at 7:48

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

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

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.