[Support request] Custom Excerpt Function Help?

Home Forums Support [Support request] Custom Excerpt Function Help?

Home Forums Support Custom Excerpt Function Help?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #265070
    Daniel

    I am using a custom function to grab text from the content, so that I don’t have to fill in the excerpt field. I am mainly using this for custom post types.
    It is working, but I can’t seem to overwrite GP’s read more link.
    Function below:

    function get_excerpt(){
    $excerpt = get_the_content();
    $excerpt = preg_replace(” (\[.*?\])”,”,$excerpt);
    $excerpt = strip_shortcodes($excerpt);
    $excerpt = strip_tags($excerpt);
    $excerpt = substr($excerpt, 0, 120);
    $excerpt = substr($excerpt, 0, strripos($excerpt, ” “));
    $excerpt = trim(preg_replace( ‘/\s+/’, ‘ ‘, $excerpt));
    $excerpt = ‘<p>’.$excerpt.’… More</p>’;
    return $excerpt;
    }

    #265255
    Tom
    Lead Developer
    Lead Developer

    I would go with the wp_trim_words() function for custom excerpts: https://codex.wordpress.org/Function_Reference/wp_trim_words

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.