WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How do I edit the_excerpt?

[Resolved] How do I edit the_excerpt?

  • Joe Hall
    Member

    @redbmedia

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Samuel Wood (Otto)
    WordPress.org Tech Dude

    @otto42

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

    Joe Hall
    Member

    @redbmedia

    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

    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!

    shawnmcmurdo
    Member

    @shawnmcmurdo

    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

    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?

    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/

    Cheers moshu!!

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

    Would do the trick.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] How do I edit the_excerpt?’ is closed to new replies.