The output filter lets you add, edit, remove, and re-order the elements that make up each post listing.
If you aren’t able to craft your desired post listing using the Display Parameters, you can use the output filter to completely customize what Display Posts displays.
Alternatively, you can use Template Parts to achieve the same customization. The approach that’s simpler for you will depend upon your theme and specific requirements.
How to Use
display_posts_shortcode_output filter includes all 11 elements used to assemble a single item in the post listing.
Many of these elements may be empty if they aren’t needed. For instance, the
$image element will be empty unless the image_size parameter is used in the shortcode and the post has a thumbnail.
$output– The full output for this post item generated by Display Posts. You’ll be returning a modified version of this.
$original_atts– The attributes provided to the shortcode. You can pass your own custom attributes to the shortcode and they will appear here, as many of the customization tutorials do.
$image– The post image.
$title– The post title.
$date– The post date.
$excerpt– The post excerpt.
$inner_wrapper– The HTML element that wraps the post (ex:
<li>for the default listing).
$content– The post content.
$class– An array of classes added to the inner_wrapper element
$author– The post author.
$category_display_text– The list of categories (or other taxonomy terms) associated with this post.
To re-arrange the elements displayed in your shortcode, change the order they appear on Line 9 above. Example: Move image after post title
You can also modify an individual element. Example: Display default image
You can add new elements into the output. Example: Display time after post date