WordPress.org

Ready to get started?Download WordPress

Forums

More on excerpt only on longer excerpts (1 post)

  1. baszer
    Member
    Posted 2 years ago #

    Hello,

    I use the script below. But it always puts the more link after the excerpt. I want to modify it a little bit so that it only shows the more link after a certain length.

    So how can I ask the lenght of the post in characters?

    So I can add that as a variable and than later ask, if $lenght > postCharacters than add the more tag

    function dynamic_excerpt($length) { // Variable excerpt length. Length is set in characters
    	global $post;
    	$permalink = get_permalink($post->ID);
    	$text = $post->post_excerpt;
    	if ( '' == $text ) {
    	$text = get_the_content('');
    	$text = apply_filters('the_content', $text);
    	$text = str_replace(']]>', ']]>', $text);
    	}
    
    	$text = mb_substr($text,0,$length). ' <a href="'.$permalink.'">more ...</a>';
    
    	echo apply_filters('the_excerpt',$text);
    	}

Topic Closed

This topic has been closed to new replies.

About this Topic