Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter shinchook

    (@shinchook)

    Ok more information…

    I found out that if my title goes over 2 lines in the box it pushes the one below it down to the following row.

    Plz help. can I get the title to truncate?

    Thread Starter shinchook

    (@shinchook)

    bump from late last night

    t31os

    (@t31os)

    Add this into your theme functions.php

    function truncate_long_titles($title) {
    	$MAX_LENGTH = 50;
    	$TERMINATOR = ' ...';
    
    	if(strlen($title) > $MAX_LENGTH){
    		$parts = explode(' ', $title);
    		$title = "";
    		$i = 0;
    
    		while(strlen($title) < $MAX_LENGTH && $i < count($parts)){
    			if(strlen($parts[$i]) + strlen($title) > $MAX_LENGTH){
    				return $title . $TERMINATOR;
    			} else {
    				$title .= ' ' . $parts[$i];
    				$i++;
    			}
    		}
    
    		return $title . $TERMINATOR;
    	} else{
    		return $title;
    	}
    }
    
    add_filter('the_title', 'truncate_long_titles');

    Set the MAX LENGTH and away you go… of course this will apply to anywhere you use the_title().

    Taken from this plugin here…
    https://www.ads-software.com/extend/plugins/truncate-title/stats/

    You don’t have to use it as a plugin, the above will work inside your theme..

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I get my post boxes a consistant size?’ is closed to new replies.