Returning data instead of echoing/printing
The problem with your code, as you mentioned, is that you are outputting the images via your print_r function, and you need to instead build a string to return, which is displayed in place of the shortcode. Give this a try: function get_media () { $attachments = get_posts([ ‘post_type’ => ‘attachment’, ‘numberposts’ => -1, ‘post_status’ … Read more