Extra word appearing at end of related posts excerpt
-
Hi – I have created a new template as per your instructions. However, the excerpt appears to be including the word “Related” at the end of each related grids item – at the end of each excerpt. I have searched my code but cannot find where this is coming from.
example at: https://bournhall.ooh-websites.co.uk/a-very-special-fathers-day-thanks-to-bourn-hall/ (see related articles at the bottom of the page).Here’s my functions.php code:
/**Add related posts section**/ add_filter( 'the_content', 'add_related_posts_after_post_content' ); function add_related_posts_after_post_content( $content ) { //check if it's a single post page. if ( is_single() ) { // check if we're inside the main loop if ( in_the_loop() && is_main_query() ) { // add your own attributes here (between the brackets [ ... ]) $shortcode = '[related_posts_by_tax posts_per_page="3" title="Related Articles" image_size="large" format="thumbnail_excerpt"]'; // add the shortcode after the content $content = $content . $shortcode; } } return $content; } /*hook in a new related posts grid*/ add_filter( 'related_posts_by_taxonomy_template', 'rpbt_thumbnail_exerpt_format_template', 10, 3 ); // Return the right template for the thumbnail_excerpt format function rpbt_thumbnail_exerpt_format_template( $template, $type, $format ) { if ( isset( $format ) && ( 'thumbnail_excerpt' === $format ) ) { return 'related-posts-thumbnail-excerpts.php'; } return $template; } // Create new format thumbnail_excerpt for use in widget and shortcode add_action( 'wp_loaded', 'rpbt_thumbnail_excerpt_format', 11 ); function rpbt_thumbnail_excerpt_format() { if ( !class_exists( 'Related_Posts_By_Taxonomy_Defaults' ) ) { return; } $defaults = Related_Posts_By_Taxonomy_Defaults::get_instance(); // Add the new format . $defaults->formats['thumbnail_excerpt'] = __( 'Thumbnail with excerpt' ); } // Return posts with post thumbnails for the thumbnail_excerpt format. add_filter( 'related_posts_by_taxonomy_shortcode_atts', 'rpbt_thumbnail_exerpt_args' ); // shortcode add_filter( 'related_posts_by_taxonomy_widget_args', 'rpbt_thumbnail_exerpt_args' ); // widget function rpbt_thumbnail_exerpt_args( $args ) { if ( 'thumbnail_excerpt' === $args['format'] ) { $args['post_thumbnail'] = true; } return $args; }
and here’s the code from my related-posts-thumbnail-excerpts.php file:
<?php if ( $related_posts ) : ?> <?php foreach ( $related_posts as $post ) : setup_postdata( $post ); // Check if size was set in widget or shortcode $size = isset( $rpbt_args['size'] ) ? $size : 'large'; ?> <div class="ooh-related-posts-grid"> <!-- post thumnail --> <div class="ooh-related-posts-grid-thumb"> <?php if ( has_post_thumbnail() ) : ?> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( $size ); ?></a> <div class="ooh-related-posts-grid-date"><?php the_modified_date(); ?></div> <!-- title --> <div class="ooh-related-posts-grid-title"> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </div> </div> <?php endif; ?> <!-- excerpt --> <div class="ooh-related-posts-grid-excerpt"> <?php the_excerpt(); ?></div> </div> <?php endforeach; ?> <?php else : ?> <p><?php _e( 'No related posts found', 'related-posts-by-taxonomy' ); ?></p> <?php endif ?>
Any help much appreciated!
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘Extra word appearing at end of related posts excerpt’ is closed to new replies.