mauriciomesquita
Member
Posted 1 year ago #
I want to limit the title of the posts related to 40 characters.
As in example:
Original title:
"The view of my title is limited to a certain number of characters"
View:
"The view of my title is limited to a certain..."
How? I thank you all for help. I am a Brazilian fan of mitcho
http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/
I would use YARPP custom templates and put the code limiting the title length there. So, first make sure that in YARPP options you're set to use custom templates. For example, "yarpp-template-example.php". Then open that file in your theme editor and find this part:
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
Replace with:
<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo substr(get_the_title(), 0, 40); ?>...</a><!-- (<?php the_score(); ?>)--></li>
I'm no expert but this should work...
Thanks @chadrew! Indeed, I think that would work!
mauriciomesquita
Member
Posted 1 year ago #
Thanks!
To limit to 40 characters and do not display words in half:
<li><a href="<?php the_permalink() ?>" rel="bookmark">
<?php
$title_cortado = explode(" ", substr(get_the_title(), 0, 40));
if(count($title_cortado) > 1) array_pop($title_cortado);
$title_cortado = implode(" ", $title_cortado)."...";
echo $title_cortado;
?> </a><!-- (<?php the_score(); ?>)--></li>
Thank you for your attention!
Congratulations