Results 1 to 6 of 6

Thread: WP Hack: Change the Post Excerpt Length

  1. #1
    Join Date
    Jul 2009
    Location
    NC, USA
    Posts
    692

    Thumbs up WP Hack: Change the Post Excerpt Length

    Writing custom excerpts for posts can be a pain, so why not just change how long they're supposed to be? This is how:

    Changing The Default WordPress Excerpt Length

    No plugin required!

  2. I used to use a plugin, but now I will give this a shot.
    Thanks
    My Blog- Let's Get Talking!
    Are you on Twitter? Let's become friends!

  3. #3
    Join Date
    Jul 2009
    Location
    Croatia
    Posts
    20
    I would not recommend this!

    You will have to do this every time you update your WP installation. It is better to write a custom function in your functions.php

    PHP Code:
    function limit_content($ctolimit$clen 280)
    {
        
    $cut substr(strip_tags($ctolimit), 0$clen);
        
    $sensible_cut_position strrpos($cut' ');
        return 
    substr($cut0$sensible_cut_position);

    and then you call it like this:

    PHP Code:
    <?php echo limit_content($ctolimit,$clen);?>
    $ctolimit - text to limit (can be get_the_content()
    $clean - number of characters to limit, default value is 280, but can be set to whatever you like. The $clean parameter is optional.

    The function returns only text without tags.

    This simple function does not break words, and the number of characters is more like a maximum for string length. This function searches for the last occurrence of a space (assumed word end ) at the end of the given text, and returns the cropped text.

  4. #4
    Join Date
    Jul 2009
    Location
    NC, USA
    Posts
    692
    Quote Originally Posted by Hrvoje View Post
    I would not recommend this!

    You will have to do this every time you update your WP installation. It is better to write a custom function in your functions.php

    PHP Code:
    function limit_content($ctolimit$clen 280)
    {
        
    $cut substr(strip_tags($ctolimit), 0$clen);
        
    $sensible_cut_position strrpos($cut' ');
        return 
    substr($cut0$sensible_cut_position);

    and then you call it like this:

    PHP Code:
    <?php echo limit_content($ctolimit,$clen);?>
    $ctolimit - text to limit (can be get_the_content()
    $clean - number of characters to limit, default value is 280, but can be set to whatever you like. The $clean parameter is optional.

    The function returns only text without tags.

    This simple function does not break words, and the number of characters is more like a maximum for string length. This function searches for the last occurrence of a space (assumed word end ) at the end of the given text, and returns the cropped text.
    Awesome. I was looking for a function that would do this but hadn't found one! Thanks.

  5. #5
    Question: why use PHP "hacks" when you can use manual excerpts? Excerpt WordPress Codex

  6. #6
    Join Date
    Jul 2009
    Location
    NC, USA
    Posts
    692
    Quote Originally Posted by Hector View Post
    Question: why use PHP "hacks" when you can use manual excerpts? Excerpt WordPress Codex
    Manual excerpts take time and some of us are lazy.

Similar Threads

  1. Replies: 27
    Last Post: 14 December, 2010, 19:57 PM
  2. anyone know how to recover hack site ?
    By SonnyCooL in forum Programming
    Replies: 8
    Last Post: 4 April, 2010, 13:41 PM
  3. Does domain registration length affect SEO?
    By kapilc in forum Web Hosting
    Replies: 3
    Last Post: 1 July, 2009, 17:37 PM
  4. How to limit the length of an output ?
    By WebEvader in forum Programming
    Replies: 11
    Last Post: 28 March, 2009, 11:17 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •