Status
Not open for further replies.
4 comments
There are multiple ways of achieving this. One of them is do the following:

Place the following function in your functions.php file:

PHP:
function ShortenText($text) {  $chars_limit = 100;  $chars_text = strlen($text);  $text = $text." ";  $text = substr($text,0,$chars_limit);  $text = substr($text,0,strrpos($text,' '));
  if ($chars_text > $chars_limit)     { $text = $text."..."; }     return $text;}

You can change the variable
Code:
$chars_limit
to the number if characters you want to limit the title to.

Now add the following code into THE LOOP of wordpress mostly in your index.php:

PHP:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
 <h1><?php echo ShortenText(get_the_title()); ?></h1>
 <div class="post-title"><?php the_content(); ?></div>
<?php endwhile; endif; ?>
 
Status
Not open for further replies.
Back
Top