Skip to content

Instantly share code, notes, and snippets.

@diegocuruma
Created March 7, 2018 11:55
Show Gist options
  • Select an option

  • Save diegocuruma/eda217ff4356bb02c26e60950b1e2d75 to your computer and use it in GitHub Desktop.

Select an option

Save diegocuruma/eda217ff4356bb02c26e60950b1e2d75 to your computer and use it in GitHub Desktop.
/**
* Limitar número caracteres conteúdo, MAS NÃO CORTA A PALAVRA AO MEIO
**/
function limitarTexto($content, $limite)
{
$contador = strlen($content);
if ($contador >= $limite) {
$content = substr($content, 0, strrpos(substr($content, 0, $limite), ' ')) . '...';
return $content;
} else {
return $content;
}
}
<!-- HTML -->
<p>
<?php echo limitarTexto(get_the_content(), 100) ;?>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment