WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do I edit the_excerpt? (9 posts)

  1. Joe Hall
    Member
    Posted 7 years ago #

    I am currently developing a custom theme for a client and have run into a tiny problem. Client requires that their category pages utilize the the_excerpt(). Therefore I have created a rather nice looking categories archive using the template hierarchy. The only small problem is that I have noticed then when using the the_excerpt() function each excerpt ends with a [...]. While I understand that this is proper English. Its not what my client wants. Instead I need to replace the [...] with a permalink to the article that says "read more here" creating the permalink was no problem at all. However the [...] is still there. any help would be greatly appreciated.

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    Look at the wp_trim_excerpt function in wp-includes/formatting.php.

  3. Joe Hall
    Member
    Posted 7 years ago #

    Thanks I was able to clear that up perfectly! And just for future reference the wp_trim_excerpt function begins on line 772 in formatting.php in v. 2.1.3

  4. hansoloz
    Member
    Posted 7 years ago #

    would you mind noting the code you used within the wp_trim_excerpt function to make this work? particularly what to put in the array_push()

    thanks!

  5. shawnmcmurdo
    Member
    Posted 7 years ago #

    I had to do the same thing this past week.
    Here is the code that I used in
    wp-includes/functions-formatting.php
    in the wp_trim_excerpt() function:

    $words = explode(' ', $text, $excerpt_length + 1);
                    if (count($words) > $excerpt_length) {
                            array_pop($words);
    !                       /* array_push($words, '[...]'); */
    !                       $morelink = '<a>ID) . '"
    [...More...]</a>';
    !                       array_push($words, $morelink);
                            $text = implode(' ', $words);
                    }
            }

    Hope that helps.
    You can see it working on my Low Vision Guide website at:
    http://www.lowvisionguide.org.

    Shawn McMurdo

  6. joffff
    Member
    Posted 7 years ago #

    Hi Shawn,

    I'm having a few problems implementing your code snippet. I can get the [...More...] tag out but how do I add the href attribute to the tag?

    When pasting your snippet I got a couple of errors around the line with

    ! $morelink = '<a>ID) . '"

    Looks like there's a few extra chars slipping in there!

    So far I've got:

    $words = explode(' ', $text, $excerpt_length + 1);
    			if (count($words) > $excerpt_length) {
    				array_pop($words);
    				/* array_push($words, '[...]'); */
                    $morelink = '<a>'.'
    					[...More...]</a>';
    					array_push($words, $morelink);
    					$text = implode(' ', $words);
    				}

    where do I go from here?

  7. moshu
    Member
    Posted 7 years ago #

    You could simply use this plugin to customize your excertpts... and no need for messing with the core files :)
    http://guff.szub.net/2005/02/26/the-excerpt-reloaded/

  8. joffff
    Member
    Posted 7 years ago #

    Cheers moshu!!

  9. randysofia
    Member
    Posted 6 years ago #

    $morelink=sprintf("<a href=\"%s\"> [read more]</a>", get_permalink());
    
    array_push($words, $morelink);

    Would do the trick.

Topic Closed

This topic has been closed to new replies.

About this Topic