the_title()
prints/retrieve the title while get_the_title()
retrieve the title.
So your code should be something like this.
<div class="case-breaking__content">
<p>
<?php
$out = strlen(get_the_title()) > 50 ? substr(get_the_title(),0,50)."..." : get_the_title();
echo $out;
?>
</p>
</div>
Note you can use the_title()
but it is not recommended here to keep the code clean.
<div class="case-breaking__content">
<p>
<?php
$out = strlen(the_title('', '', false)) > 50 ? substr(the_title('', '', false),0,50)."..." : the_title('', '', false);
echo $out;
?>
</p>
</div>
The above code will place ...
after 50 characters, However if you want to place it after certain numbers of words, you should go for wp_trim_words()
.
<div class="case-breaking__content">
<p>
<?php echo wp_trim_words(get_the_title(), 8, '...'); ?>
</p>
</div>
I hope this may help.