Daniel Laursen
asked 10 years ago

Hey again.  

 

The theme is working great, but recently, it has been kinda frustrating to have the excerpt length limited by a specific amount of words. Is there any way to limit the excerpt length using a max. amount of characters instead? 

I’m talking about the excerpt length being used here: REMOVED (not the slider – it is a plugin. But everything under the slider).   

 

Also, is there any way to limit the excerpt with max. amount of characters without truncating (ensuring that a word like “information” doesn’t show up like “informa…read more” even though adding the last few characters will break the character limit). I’ve seen it done on other sites, by adding a function for it.   

 

I look forward to hearing from you.

4 Answers
DominicStaff
answered 10 years ago

You can try the following solution.
Add the following code to the functions.php file. (line 1140)

function get_excerpt($count){
  $permalink = get_permalink($post->ID);
  $excerpt = get_the_content();
  $excerpt = strip_tags($excerpt);
  $excerpt = substr($excerpt, 0, $count);
  $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
  return $excerpt;
}

Change the ‘more’ to what text you want to display.
– Open the dw-focus-recent-post.php file in the folder path “wp-content\themes\dw-focus\inc\widgets”. Find the line 110 & 222.
Replace the following code

<?php the_excerpt(); ?> 

With new code:

<?php echo get_excerpt(45); ?>

– Open the dw-focus-categories.php file. Find the line 298 & 412.
Replace the following code

<?php the_excerpt(); ?> 

With new code:

<?php echo get_excerpt(45); ?>

Note: Change the value 45 to how many characters you want to display.
Hope this helps !

DominicStaff
answered 10 years ago

Apologies for the delay in replying to you. To resolve this issue, you can add the following code to the function.php file (wp-content\themes\dw-focus)

function fix_the_excerpt($text) {
  return str_replace('[...]', '...', $text);
}
add_filter('the_excerpt', 'fix_the_excerpt');

function my_excerpt_length($length) {
  return 10; // Or whatever you want the length to be.
}
add_filter('excerpt_length', 'my_excerpt_length');

Hope this helps !

Daniel Laursen
replied 10 years ago

I wrote a reply. Please check it out below.

Daniel Laursen
answered 10 years ago

Thanks for finally getting back to me.
 
I tried adding that part to the function.php, but it didn’t really work. 
Are you sure I shouldn’t do anything else but add it to the function.php? 

Daniel Laursen
answered 10 years ago

This worked perfectly! 
 
Thanks a lot for the fantastic support! 

Powered by DW Question & Answer Pro