WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 this code for the_excerpt :

function get_excerpt(){
    $excerpt = get_the_content();
    $excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
    $excerpt = strip_shortcodes($excerpt);
    $excerpt = strip_tags($excerpt);
    $excerpt = substr($excerpt, 0, 640);
    $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
    $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
    $excerpt = $excerpt.'<a class="read-more" <a href="'. get_permalink($post->ID) . '">read more.</a>';
    return $excerpt;

I want to disable from one post the_excerpt. I think that this part of function helps but this is not happened.

if( in_array( $post->ID, array(post_ID) ) ) 
share|improve this question
up vote 3 down vote accepted

First of all, WordPress already includes a function for displaying excerpts: the_excerpt()

Secondly, your second piece of code isn't actually displaying anything. You need to use the echo statement for displaying text on the page. However, WordPress provides functions that actually display the content and excerpt on the page: the_content() and the_excerpt(), respectively.

if( in_array( $post->ID, array(post_ID) ) ) 
share|improve this answer
thanks for the answer. In the second piece of code , i don't want to display anything. Actually, i want this : If the post have this post_ID, then apply the_content, else apply the_excerpt. What i am doing wrong? – MikeD Dec 8 '12 at 10:34
I write this part of code, inside the loop of my index.php <?php if(in_array( $post->ID,array(333))) { the_content(); } else { echo get_the_excerpt();}?> and for this case has enabled the [..] of the_excerpt(), and i don't want this. – MikeD Dec 8 '12 at 13:09
Oh i have done a big mistake. In my functions.php, i have this code : function get_excerpt(){ $excerpt = get_the_content(); and in the loop of index.php : echo get_the_content(); } else { echo get_excerpt();}. I replaced the variables correctly and it' works. :) – MikeD Dec 8 '12 at 13:38
This code applied for post, how to enable for categories? – MikeD Dec 8 '12 at 14:59

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.