Site logo

Archived topic

Custom excerpt length on featured post

11 replies · Started by Karel on October 21, 2021

Viewing posts 1–12 of 12

Hi there,

How are the Excerpts being created ? Are they a manual excerpt or is some other function generating them. As when i check the single post i cannot see that text in the content.

Hi David,

These are normal automatic excerpts, not manual.
Not sure what you mean when you say you don't see the text in the content, the excerpt is exactly the same as the first words of the post content and was generated automatically.

The post was made sticky to make it the first post in the blog
In the customizer, the option "make first post featured" was turned on

Thanks for looking into it

Sorry my bad ... i am not sure what i was looking at :)

I done a quick test with a Sticky Post, the filter to change the number of posts on the first page, and the Excerpt length filter and it worked.

This is how my two functions look:

add_action( 'pre_get_posts', 'tu_change_posts_per_page', 1 );
function tu_change_posts_per_page( &$query ) {
    if ( ! is_main_query() ) {
        return;
    }

    if ( ! $query->is_paged ) {
        $query->set( 'posts_per_page', 15 ); // First page 15 posts
    }
}

add_filter( 'excerpt_length', 'tu_featured_excerpt_length', 50 );
function tu_featured_excerpt_length( $length ) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    global $wp_query;

    if ( 1 == $paged && 0 == $wp_query->current_post ) {
        return 100; // First post
    }

    return $length;
}

Thanks.
Can't get it to work unfortunately.
I added your snippet in the extra CSS, but it has no effect, not the excerpt length and not on the nr of posts.
(Other modifications in the extra CSS do work)

Not sure what I'm doing wrong...

Ah, of course...Sorry.

Both snippets work perfectly.
Thank you very much!

Really glad to hear that!

Hey guys, this answer helped me with half my problem... the other half is this: how would I go about making the title of the featured post bigger than the rest?

Hi Oliver,

Can you open a new topic with regard to the other issue?

No problem. Here is the Link in case someone who´s interested lands in here

Thank you, Oliver! Let's continue in the new thread.

This archived topic is closed to new replies.