This checks the number of characters and hide the button server-side in content.php:
<?php
$excerpt = get_the_excerpt();
$excerpt_length = strlen($excerpt);
$excerpt_limit = 100; // Match the limit set in functions.php
// only for debugging:
var_dump($excerpt);
var_dump($excerpt_length);
?>
<div class="news-main">
<?php the_excerpt(); ?>
</div>
<?php if ($excerpt_length >= $excerpt_limit) : ?>
<div class="news-read">
<a href="<?php echo get_permalink($post->ID); ?>" target="_blank" rel="noopener" class="Read">Read More</a>
</div>
<?php endif; ?>
If your file contains the_excerpt();, comment it out.
<?php // the_excerpt(); ?>
Edit:
Your output looks fine. Can you please remove my code and replace it with <?php the_excpert(); ?> again.
Please update your code in your functions.php:
function my_excerpt_length($length) {
return 100; // Set excerpt length to 100 words
}
add_filter('excerpt_length', 'my_excerpt_length', 20, 1);
Your function should be defined before calling add_filter(). Otherwise, PHP may throw an error if it can’t find my_excerpt_length.
If another plugin or theme is overriding excerpt_length with a later priority, your function might not take effect. Therefore add 20, 1