Title: Truncate Nextgen description
Last modified: August 19, 2016

---

# Truncate Nextgen description

 *  [mfal55](https://wordpress.org/support/users/mfal55/)
 * (@mfal55)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/truncate-nextgen-description/)
 * Aaack. I can’t seem to figure out what I’m doing wrong. I’m trying to truncate
   my Nextgen gallery image descriptions and I’ve managed to truncate them, but 
   it breaks the rest of my page. Is there anyone who could look at this piece of
   my code and tell me what the heck I’m doing wrong? Thanks in advance.
 *     ```
       <?php foreach ( $images as $image ) : ?>
       ...stuff...
   
       <?php
       function truncate($string, $del) {
         $len = strlen($string);
         if ($len > $del) {
           $new = substr($string,0,$del)."...";
           return $new;
         }
         else return $string;
       }
   
       $arg = "$image->description";
   
       ?>						
   
       <p><?php echo truncate($arg, 130)."n"; ?></p>	
   
       ...more stuff....
       <?php endforeach; ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [mfal55](https://wordpress.org/support/users/mfal55/)
 * (@mfal55)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/truncate-nextgen-description/#post-1919350)
 * I also tried this method, but also breaks the page
 *     ```
       <?php
       function truncate($string, $max = 20, $replacement = '')
   
       {
   
           if (strlen($string) <= $max)
           {
               return $string;
           }
           $leave = $max - strlen ($replacement);
           return substr_replace($string, $replacement, $leave);
       }
       $descript = $image->description;
       echo truncate($descript,10,'...');
       ?>
       ```
   
 * My php must be wrong in some way, but my knowledge in this area is super limited.
   
   Any help is greatly appreciated.
 * Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Truncate Nextgen description’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [mfal55](https://wordpress.org/support/users/mfal55/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/truncate-nextgen-description/#post-1919350)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
