Displaying attachments in posts

The main requirement of this plugin was to attach files to posts and let users download them from the post page. So far, we have created the background to save and display the attachments. Now, it's time to implement the main requirements by displaying them after the content of each post.

At the start of this chapter, we created a plugin to use the the_content filter and add dynamic content after the post. The same technique will be used in this scenario. Let's consider the following code for the implementation of the the_content filter:

add_filter( 'the_content', 'wpqpa_file_attachment_display' );function wpqpa_file_attachment_display( $content ){  global $post;  if( is_singular( 'post' ) ){ return $content ...

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.