I wish to use the excerpt of a post in the meta description for better SEO, so I am using the get_the_excerpt() function to get the post's excerpt. However, I noticed that at the end it is adding [...] when the post's content is not separated by the More separator, and when it is longer than the configured maximum length.

Is there a clean way to remove this [...] in the end of the excerpt? The function doesn't seem to have a boolean parameter to specify whether you want it, or anything of that sort.

** UPDATE **

I do not want to remove the [...] from the main index.php. I just want to remove it in certain instances (in the meta description), and leave it in others. So the hook solution does not work in this case.



2 Answers 2


Don't use get_the_excerpt. Just do something like:

if (is_singular() && isset($post->post_excerpt)) {
    echo '<meta name="description" content="'.esc_attr($post->post_excerpt).'" />';

$post is populated long before the Loop. For "single" pages it will be populated with the post to be displayed. You can grab it very early in the page load. For other types of pages-- archives, capital "P" Pages-- it may not have the value you expect, so watch it.


  1. That assumes that your posts all have actual excerpts. Nothing will be auto-generated from post content.
  2. I have no idea how you theme works. You may need to edit a theme file. You may need to build a function and hook it to a theme hook or to wp_head.
  • I have no problem with caveat 2 because I built the theme myself. I do have a problem with caveat 1 however, because my bloggers often don't put the 'more' separator in their post, which is often the case when the [...] appears. Maybe I can use the post's content in some way and simulate what get_the_excerpt() is doing, i.e. if $post->post_excerpt is an empty string I use the full content and truncate it myself to the maximum excerpt length? Where can I find all the attributes of the $post variable? And how can I get the maximum excerpt length parameter from wordpress with PHP?
    – jbx
    Commented Jan 2, 2013 at 12:58
  • "Maybe I can use the post's content in some way and simulate what..." Yes, of course. That is a pretty simple switch, but the content before the <!--more--> is not the same as the excerpt. The two are very different.
    – s_ha_dum
    Commented Jan 2, 2013 at 14:38
  • Yes thats understood. So one would need to get the excerpt, and if its empty use the content and truncate it to the maximum.
    – jbx
    Commented Jan 8, 2013 at 11:08
  • That's right. Sounds like you have it.
    – s_ha_dum
    Commented Jan 8, 2013 at 14:41
function change_excerpt_more( $more ) {
    return '[.....]';
add_filter('excerpt_more', 'change_excerpt_more');

You can replace '[.....]' with whatever you want or with '' for nothing.

  • Yes, but that will also effect the main posts that get listed on the main index page, where I do want the more string to appear.
    – jbx
    Commented Dec 30, 2012 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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