skip to Main Content

I am getting post excerpt content with this code.

echo the_excerpt();

And also I am getting full post. content with this code

$content = get_the_content();
echo $content;

But I don’t want full content. I want to show the content without the excerpt content.

if the full content is this:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry."

excerpt is this:
"Lorem Ipsum"

then the content without excerpt will be show this:
"is simply dummy text of the printing and typesetting industry."

I want to set word count while displaying the content without excerpt.

I have tried multiple code to achieve this but not get any solution. Kindly help me with this.

2

Answers


  1. Chosen as BEST ANSWER

    The above code is not replacing HTML tags. I figured out some code which can replace tag also...

    echo "<div id='precont'>";
    $content = get_the_content();
    echo substr($content, 0, 250);
    echo "...<a href='#viewmore'>View More</a>";
    echo "</div>";
    
    
    
    
    echo "<div id='viewmore'>";
    $prefix = substr($content, 0, 250);
    $result = str_replace($prefix, "", $content);
    echo $result;
    echo "</div>";
    

  2. You can call content function like that:

    the_content( null, true );
    

    null – to do not show "read more", and true – to remove initial text before <–more–>:
    More in docs:
    https://developer.wordpress.org/reference/functions/the_content/

    Or if above not working for you, you can use not a nice solution, but 100% working with str_replace:

    $excerpt = get_the_excerpt();
    $content = get_the_content();
    
    $final_content = str_replace( $excerpt, '', $content );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search