Skip to content

Instantly share code, notes, and snippets.

@pablocattaneo
Created February 4, 2016 15:11
Show Gist options
  • Save pablocattaneo/9cd90e5cc29435dcacc8 to your computer and use it in GitHub Desktop.
Save pablocattaneo/9cd90e5cc29435dcacc8 to your computer and use it in GitHub Desktop.
Crea un custom excerpt que corta el contenido por cantidad de caracteres, esta función tiene que escribirse en function.php Create a custom excerpt that cuts the content acording the number of charcaters define, Source: http://smallenvelop.com/4-ways-to-limit-post-excerpt-length-in-wordpress/
<?php
function get_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 50); // characters number
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
return $excerpt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment