Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #220345

    Hi There

    I want to show the teaser only from blog posts on the front page of my site. I know you can set the “insert more” tag on the wysiwg editor, but I don’t trust my content creators to use it.

    Is there any way to force the page only to display a teaser and read-more link?

    #220839

    Hey downunderal!

    You can use following code:

    
    add_filter( 'post-format-standard', 'avia_category_content_filter', 15, 1);
    function avia_category_content_filter($current_post)
    {
    if(!is_single())
    {
    	$current_post['content'] =  get_the_excerpt();
    	$current_post['content'] .= $current_post['content'].'<div class="read-more-link"><a href="'.get_permalink().'" class="more-link">'.__('Read more','avia_framework').'<span class="more-link-arrow">  &rarr;</span></a></div>';
    }
    return $current_post;
    }
    

    to display the excerpt text (excerpt field on the post editor page) and a read more button. If you want to display a static teaser text instead use this code

    
    add_filter( 'post-format-standard', 'avia_category_content_filter', 15, 1);
    function avia_category_content_filter($current_post)
    {
    if(!is_single())
    {
    	$current_post['content'] =  'My custom text.';
    	$current_post['content'] .= $current_post['content'].'<div class="read-more-link"><a href="'.get_permalink().'" class="more-link">'.__('Read more','avia_framework').'<span class="more-link-arrow">  &rarr;</span></a></div>';
    }
    return $current_post;
    }
    

    and instead of “My custom text.” insert your custom teaser text.

    Cheers!
    Peter

    #223741

    Dude,
    in which file do you place the code?
    Thanks!

    #223965

    Hi!

    into Functions.php file. You can open it in Appearance > Editor

    Cheers!
    Yigit

    #224094

    Thanks Yigit! Works great.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Force posts to show teaser only on front page’ is closed to new replies.