How to remove the […] from the excerpt
-
Hi,
Instead of using the_content() and other codes, i have used the_excerpt() code for the posts to be cut off on the home page. However i am now finding that at the point where the article is cut off, i get a […] sign. Is there any way that i can remove it?
-
Do you want it to be gone, or do you want something else in its place? You could use the more tag instead.
I want it to be gone…i want to completely remove it
I’m having this issue too, I’d like to remove the <p> that comes after that too so that the read more link immediately follows the excerpt without dropping down a line.
ok, if anyone here is interested in the <p></p> solution, i found it:
<?php remove_filter(‘the_excerpt’, ‘wpautop’); ?>
that gets rid of the <p></p> now if i can only get rid of the […]
??
You can just re-write the excerpt function in your theme functions file…
Like this…
function wp_new_excerpt($text) { if ($text == '') { $text = get_the_content(''); $text = strip_shortcodes( $text ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $text = nl2br($text); $excerpt_length = apply_filters('excerpt_length', 55); $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '[...]'); $text = implode(' ', $words); } } return $text; } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'wp_new_excerpt');
Just change this line…
array_push($words, '[...]');
You can also change the character limit here…
$excerpt_length = apply_filters('excerpt_length', 55);
hm… I tried that but my functions file doesn’t have that in it. so I added it verbatim like this:
<?php
function wp_new_excerpt($text)
{
if ($text == ”)
{
$text = get_the_content(”);
$text = strip_shortcodes( $text );
$text = apply_filters(‘the_content’, $text);
$text = str_replace(‘]]>’, ‘]]>’, $text);
$text = strip_tags($text);
$text = nl2br($text);
$excerpt_length = apply_filters(‘excerpt_length’, 55);
$words = explode(‘ ‘, $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
array_push($words, ‘…’);
$text = implode(‘ ‘, $words);
}
}
return $text;
}
remove_filter(‘get_the_excerpt’, ‘wp_trim_excerpt’);
add_filter(‘get_the_excerpt’, ‘wp_new_excerpt’);
?>I just changed
array_push($words, ‘[…]’);
to
array_push($words, ‘…’);
and it kinda worked on the page, but something else in the above code interfered with publishing. I got an error having to do with functions.php and a header already being called or something like that.
so I took it out. ??
Is there a way to add JUST the array thing?
I assume this
<?php
function wp_new_excerpt($text)
array_push($words, ‘…’);
?>isn’t right, and I’m afraid to try it.
Why not this?
function trim_excerpt($text) { return rtrim($text,'[...]'); } add_filter('get_the_excerpt', 'trim_excerpt');
I tested it in my function.php and it works like a charm. Maybe I’m missing something?
Of course, my code removes everything ( and it doesn’t deal with the <p> problem above ) but you could add back anything you want by concatenating the string like so: `
return rtrim($text,'[…]’).’whateveryouwantgoeshere’;`It is also possible to do the same with
str_replace
orpreg_replace
instead ofrtrim
but I’m not sure the extra complexity is worth it.Oh, and visiblemedia, you aren’t inserting into the database here so it isn’t really possible to do any real damage. This filters only works on the displayed text. It doesn’t alter the information in the database. About the worst that can happen is that you get a screwy page view for a few minutes.
No the function won’t exist in your themes function file, that was the point, the example was one you can add in, as you have done..
It’s the same code i use on my site except i changed the function name to something more obvious for the example…
I still use […], but i just tested it with … and it worked no problem…
You sure you didn’t delete a ‘ by accident or something silly when testing?
Of course the above solution may be better suited in this case, the example provided by myself will give you a bit more control over the rest of the excerpt function though, if you need it… such as character limit.
Confession: I’m having second thought about my function. I may have tested it improperly. I’ll have to fiddle with it more later.
Ok I tested it a bit more and it still seems to work.
hm… well that didn’t work, my exerpts ended up looking like this:
Last Chance for Freebie Play
February 28, 2009 | By RotoRob | Comments (0)Warning: rtrim() [function.rtrim]: Invalid ‘..’-range, no character to the left of ‘..’. in /nfs/c04/h01/mnt/60416/domains/rotorob.com/html/wp-content/themes/RotoRob_v7/functions.php on line 32
Warning: rtrim() [function.rtrim]: Invalid ‘..’-range, no character to the right of ‘..’. in /nfs/c04/h01/mnt/60416/domains/rotorob.com/html/wp-content/themes/RotoRob_v7/functions.php on line 32
If you don’t want your kid to wind up like this, teach him how to play fantasy sports properly. In the past couple of weeks, we’ve brought you articles designed to help you with your strategy when playing hockey or basketball fantasy leagues on Draftbug. Well, today (i.e., February 28) is your last chance to take advantage […] moreI wonder if the stuff in the template is conflicting with the stuff in the functions.php?
I have this in my template:
<?php $count++; ?> <?php if ($count < 2) : ?> <?php the_content() ?> <?php else : ?> <?php remove_filter('the_excerpt', 'wpautop'); ?> <?php the_excerpt();?> <a href="<?php the_permalink() ?>">more</a> <?php endif; ?>
where you would normaly find this:
<?php the_content() ?>
I do that so that I can display the first post in full, followed by 4 excerpts.
maybe the:
<?php remove_filter('the_excerpt', 'wpautop'); ?> <?php the_excerpt();?>
in the template is conflicting with the
function trim_excerpt($text) { return rtrim($text,'[...]'); } add_filter('get_the_excerpt', 'trim_excerpt');
in the functions.php?
Well, you don’t want to be trying multiple solutions at the same time. Looks like t31os suggested a way to remove the ‘[…]’ and I suggested a way to remove it. You decided to try
remove_filter('the_excerpt', 'wpautop');
in order to remove the paragraph tags. That is three separate solutions, or attempts at solutions. Try them one at a time, at least at first. Then mix and match carefully.What exactly is on line 32 of your functions file? And what software did you use to edit the file?
hmm, I commented out:
<?php remove_filter('the_excerpt', 'wpautop'); ?>
from the template files (archive.php and index.php) and added:
function trim_excerpt($text) { return rtrim($text,'[...]'); } add_filter('get_the_excerpt', 'trim_excerpt');
back into the functions.php file and got the same kind of error.
then I tried adding this:
<?php function trim_excerpt($text) { return rtrim($text,'[...]'); } ?>
to this:
<?php $count++; ?> <?php if ($count < 2) : ?> <?php the_content() ?> <?php else : ?> <?php remove_filter('the_excerpt', 'wpautop'); ?> <?php the_excerpt();?> <a href="<?php the_permalink() ?>">more</a> <?php endif; ?>
so that it looks like this:
<?php $count++; ?> <?php if ($count < 2) : ?> <?php the_content() ?> <?php else : ?> <?php remove_filter('the_excerpt', 'wpautop'); ?> <?php function trim_excerpt($text) { return rtrim($text,'[...]'); } ?> <?php the_excerpt();?> <a href="<?php the_permalink() ?>">more</a> <?php endif; ?>
in the index.php and archive.php file and got all sorts of other errors… something about “cannot re declare the_exerpt” or something like that. and my sidebar disappeared.
ooops, double post by accident, sorry
- The topic ‘How to remove the […] from the excerpt’ is closed to new replies.