Excerpt function
-
Hi, I noticed that excerpt function for blog post don’t work.
I tried to change “toujours_excerpt_length” in functions.php, but it doesn’t do anything.
So I’m trying to dig the code and find where can be the problem, I think in content.php, but I’m not so sure.
The funny is that the Advanced Excerpt plugin works, but if possible, I prefer to also have the original function too, so if needed I can make a manual expcert.How can I fix this little bug?
J
-
Hi J,
Could you explain a little more what you mean that the excerpt function doesn’t work? What steps are you following and what exactly happens?
Also, it would be helpful if you could share the URL of the site you’re working on. Thanks!Hi, thanks for your reply
I mean that if I do a blog post and I specify an excerpt inside the post I can’t see it in the blog page, for example.
I made a post with this inside:Could you explain a little more what you mean that the excerpt function doesn’t work? What steps are you following and what exactly happens? Also, it would be helpful if you could share the URL of the site you’re working on. Thanks!then I specify the excerpt like this:
Could you explain?
On the blog page I see all the post and not the excerpt, but if I switch to twentytwentyone theme, I can see the post with the excerptSure the url is http://www.goccediveleno.it, not yet finished, I’m working on it … tell me if you maybe need some English post or some screen to see what happen
Thank you again
J
Different themes have different display styles when it comes to handling excerpts.
In this case, you can duplicate that functionality by splitting your post up with the More block: https://wordpress.org/support/article/more-block/
Thank you @macmanx for your reply.
Actually I don’t like more-block, just because is a writer site/blog, you know, I want to create curiosity by writing a little summary or synopsis of the article, without necessarily reporting the first bit of it.
Do you know a way to “substitute” from normal behavior to “excerpt mode”?
I mean, I’m trying to modify the code and I found excerpt hook filter in functions.phpfunction toujours_excerpt_length( $length ) { return 35; } add_filter( 'excerpt_length', 'toujours_excerpt_length', 999 ); /** * Replaces the excerpt "more" text by a link */ if ( ! function_exists( 'toujours_excerpt_continue_reading' ) ) { function toujours_excerpt_continue_reading() { return '… <a href="' . esc_url( get_permalink() ) . '">' . sprintf( esc_html__( 'More', 'toujours' ), '<span class="screen-reader-text"> "' . get_the_title() . '"</span>' ) . '</a>'; } } add_filter( 'excerpt_more', 'toujours_excerpt_continue_reading' );Now, I’m pretty sure that the part that I need to modify is inside content.php file in template-parts folder, so I see this
<?php if ( '' !== $post->post_content ) { ?> <div class="entry-content"> <?php the_content( sprintf( /* translators: %s: Name of current post. */ wp_kses( __( 'Continue reading %s <span class="meta-nav">→</span>', 'toujours' ), array( 'span' => array( 'class' => array() ) ) ), the_title( '<span class="screen-reader-text">"', '"</span>', false ) ) ); ?> <?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . esc_html__( 'Pages:', 'toujours' ) . '</span>', 'after' => '</div>', 'pagelink' => '<span class="page-links-num">%</span>' ) ); ?> </div><!-- .entry-content --> <?php } ?>and if I remove this part
<?php the_content( sprintf( /* translators: %s: Name of current post. */ wp_kses( __( 'Continue reading %s <span class="meta-nav">→</span>', 'toujours' ), array( 'span' => array( 'class' => array() ) ) ), the_title( '<span class="screen-reader-text">"', '"</span>', false ) ) ); ?>No article content is showed, for this I think is the right section, but I can’t understand why the excerpt is not showed, I mean, I set it up inside the article post but is not even showed, but if I install a plug-in “Advanced Excerpt” and I set to make an excerpt after 20 chars (space included) nothing happen, but if I set this option on “Generate excerpts even if a post has a custom excerpt attached.” then every post is trimmed after 20 chars and is correct. So this tell me that Toujours theme use the article content like an excerpt, or this’s what I think. I don’t know if I have explained myself well.
And I also noticed that featured content are reported with the correct excerpt, so like you said, every template have a different way to show excerpt. I searched a bit and featured content by jetpack that call some “post” function and report an “array”, but I’m not an expert on WordPress, so I need some help, and I’ve to ask
For these reasons I think that $post->post_content is doing the “bad job”, also because the “Advanced Excerpt” plug-in automatically hooks on the_excerpt() and the_content() but I need to force it in order to use it.So, let assume that a theme don’t have excerpt support, how can I add this?
Any idea?
J
Hello J,
Actually I don’t like more-block, just because is a writer site/blog, you know, I want to create curiosity by writing a little summary or synopsis of the article, without necessarily reporting the first bit of it.
It is possible to hide the content presented before the more block as seen here:
https://wordpress.com/support/wordpress-editor/blocks/more-block/#block-settings-panel
So, let assume that a theme don’t have excerpt support, how can I add this?
This would need some custom development made to theme. Ideally you would work off of a child theme to make those changes.
Please see the theme developers handbook here: https://developer.wordpress.org/themes/
I hope this helps!
Hi @aleone89
Thank you, but that particular option is not working like expected with this template, perhaps because it is old or maybe for some other modifications, but is a good starting point for me.Yes I’m working on a child theme, some little fix or modification are always needed, I think.
I’ll try to find a way to implement this basic function, I made some test and worked on blog page, but when I enter into the article I always see the continue reading link, so, I’ve to figure out how to show excerpt only on blog page and not inside the articleThanks for the link, I’ll look also inside it
Do you know a good free theme where I can “extract” the excerpt function? I tried to take a look at twentytwentyone but seems to be “splitted” in more than one file
The topic ‘Excerpt function’ is closed to new replies.
