The Output Filter

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

The 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.

  1. $output – The full output for this post item generated by Display Posts. You’ll be returning a modified version of this.
  2. $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.
  3. $image – The post image.
  4. $title – The post title.
  5. $date – The post date.
  6. $excerpt – The post excerpt.
  7. $inner_wrapper – The HTML element that wraps the post (ex: <li> for the default listing).
  8. $content – The post content.
  9. $class – An array of classes added to the inner_wrapper element
  10. $author – The post author.
  11. $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

Recent Tutorials