Let’s say you are using Display Posts to list products and would like to include ” in Peterborough” to the end of each title within the link. We’ll use the output filter to add a new parameter, after_title
, and include that as part of the title.
Usage: [display-posts after_title=" in Peterborough"]
This code snippet goes in a core functionality plugin or Code Snippets.
/**
* Display Posts - Extra text after title
* @link https://displayposts.com/2019/10/09/add-extra-text-after-title/
*/
function be_dps_after_title( $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
if( !empty( $original_atts['after_title'] ) ) {
$title = str_replace( '</a>', esc_attr( $original_atts['after_title'] ) . '</a>', $title );
$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
}
return $output;
}
add_filter( 'display_posts_shortcode_output', 'be_dps_after_title', 10, 11 );
Filters used:
pre_display_posts_shortcode_output