get_the_excerpt() issues – returns the excerpt twice or not at all?
get_the_excerpt() issues – returns the excerpt twice or not at all?
get_the_excerpt() issues – returns the excerpt twice or not at all?
Include image in excerpt
How to apply excerpt length only on front end?
Pull it out of the content-part. That would be the easiest. <section id=”featured”> <?php // Start custom loop $args = array( ‘post_type’ => ‘project’, ‘posts_per_page’ => 5, ); $featured_query = new WP_Query( $args ); while ( $featured_query->have_posts() ) : $featured_query->the_post(); ?> <article class=”project”> <?php if ( has_post_thumbnail() ) { the_post_thumbnail( ‘post-thumbnail’, array( ‘class’ => ‘featured’ … Read more
To determine where you are inside the loop in this filter, you will have to access the global main query. Like this: add_filter (‘excerpt_length’, ‘wpse268679_custom_excerpt_length’); function wpse268679_custom_excerpt_length ($length) { // access main query global $wp_query; // do this only for the main loop and the first post in the query if (is_main_query() && ($wp_query->current_post == … Read more
How to show post content before read more tag (excerpt) for password protected posts?
Make a Read More toggle in the_content on single-product in Woocoomerce
Allow me to purpose an alternative. Instead of setting the excerpt’s length for all the posts, let’s just trim it for individual posts. Shall we? For this very purpose, we can use get_the_excerpt filter. If you look at the corresponding page about this filter, you notice that the code example is using is_attachment(), which means … Read more
Try this and place in your functions.php file: function custom_excerpt_length( $length ) { return 35; } add_filter( ‘excerpt_length’, ‘custom_excerpt_length’, 999 ); function excerpt_more( $more ) { return sprintf( ‘%2$s’, get_permalink( get_the_ID() ), __( ‘Read More’, ‘textdomain’ ) ); } add_filter( ‘excerpt_more’, ‘excerpt_more’ );
Why not use substr? Function example that returns shortened excerpt: function shortened_excerpt() { echo substr(get_the_excerpt(), 0, 30) . “…”; }