最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

excerpt - Remove more or [...] text from short post

programmeradmin4浏览0评论

I use a theme that have a character limit for shortpost and show [...] at the end of character limit.

I want to remove this, so I search for the_excerpt(); and replace with the_content();

The problem solve with normal content but still have problem with image post type and there is <?php the_excerpt(); ?> that when I change this my shortpost act like full post and it's not related to the length of post.

I try to open all PHP files in theme and looking for key words like: limit, length, excerpt for find where is the code that define the length of shortpost even search for "[...]" in all files and language but I don't know where is that come from.

But all I find is some line of code in function.php

if ( ! function_exists( 'string_limit_words' ) ) :
function string_limit_words($str, $limit = 18 , $need_end = false) {
    $words = explode(' ', $str, ($limit + 1));
    if(count($words) > $limit) {
        array_pop($words);
        array_push($words,'...');
    }
    return implode(' ', $words);
}
endif;

And when I increase 18 nothing change!

What code I must looking for?

I use a theme that have a character limit for shortpost and show [...] at the end of character limit.

I want to remove this, so I search for the_excerpt(); and replace with the_content();

The problem solve with normal content but still have problem with image post type and there is <?php the_excerpt(); ?> that when I change this my shortpost act like full post and it's not related to the length of post.

I try to open all PHP files in theme and looking for key words like: limit, length, excerpt for find where is the code that define the length of shortpost even search for "[...]" in all files and language but I don't know where is that come from.

But all I find is some line of code in function.php

if ( ! function_exists( 'string_limit_words' ) ) :
function string_limit_words($str, $limit = 18 , $need_end = false) {
    $words = explode(' ', $str, ($limit + 1));
    if(count($words) > $limit) {
        array_pop($words);
        array_push($words,'...');
    }
    return implode(' ', $words);
}
endif;

And when I increase 18 nothing change!

What code I must looking for?

Share Improve this question edited Sep 21, 2014 at 12:09 Sven 3,6841 gold badge35 silver badges48 bronze badges asked Sep 21, 2014 at 11:24 AriomanArioman 1531 gold badge2 silver badges9 bronze badges
Add a comment  | 

6 Answers 6

Reset to default 28

The codex is your friend and should be your first stop :-)

The [...] is added by the_excerpt(). There is a filter supplied called the excerpt_more filter that is specifically included to customize the read more text after the excerpt

To remove the [...] after the excerpt text, you can do the following

function new_excerpt_more( $more ) {
    return '';
}
add_filter('excerpt_more', 'new_excerpt_more');

As others have already pointed out, using the excerpt_more filter hook is the right way to go.

Just wanted to add that you don't have to write a function that returns an empty string. WordPress has a few built in functions to return true, false, zero, null, empty string or empty array.

In this case we need __return_empty_string()

You can add this code to your plugin or to your theme's functions.php:

<?php 
// This will add a filter on `excerpt_more` that returns an empty string.
add_filter( 'excerpt_more', '__return_empty_string' ); 
?>

You should add this to your functions.php

    function custom_excerpt_more( $more ) {
    return '';//you can change this to whatever you want
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );

Also, using the_excerpt has the advantage that automatically cleans the content, and deletes all images, and other HTML tags.

You can read more here

If you also want to modify the length of the excerpt, you can add this snippet to your functions.php:

function custom_excerpt_length( $length ) {
    return 20;//change the number for the length you want
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

You can read more about this here

that is work for me !

function change_excerpt( $text )
{
    $pos = strrpos( $text, '[');
    if ($pos === false)
    {
        return $text;
    }

    return rtrim (substr($text, 0, $pos) );
}
add_filter('get_the_excerpt', 'change_excerpt');

'excerpt_more' is a WordPress hook. It returns the content excerpt. To remove the [...] after the excerpt text, you can return blank like below or your custom requirements. Use this code on function.php

function custom_excerpt_more( $excerpt ) {
    return '';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );

Try to create a new function in your functions.php:

function custom_excerpt() {
 $text=preg_replace( "/\\[&hellip;\\]/",'place here whatever you want to replace',get_the_excerpt());
echo '<p>'.$text.'</p>';
}

Then use the new function on your page.

发布评论

评论列表(0)

  1. 暂无评论