0

When uploading an image to a post, I see ALL of the images I've uploaded. Is there a function I can use so that only the images attached to that post appear?

I have no need to use images from previous posts... Please let me know if this makes any sense!

  • This actually works but for the "Add Media" button on the toolbar of the actual post. It looks like the theme I'm using does not implement the default WP upload. So there is no option to select "Uploaded to this Page." – tryin2learn May 12 '17 at 22:34
0
    add_action( 'admin_footer-post-new.php', 'firmasite_mediapanel_lock_uploaded' );
    add_action( 'admin_footer-post.php', 'firmasite_mediapanel_lock_uploaded' );
    function firmasite_mediapanel_lock_uploaded() { ?>
  <script type="text/javascript">
    jQuery(document).on("DOMNodeInserted", function(){
        // Lock uploads to "Uploaded to this post"
        jQuery('select.attachment-filters [value="uploaded"]').attr( 'selected', true ).parent().trigger('change');
    });
  </script>
<?php }

Just place that into your child-theme's functions.php file :)

  • Hey, tryin2learn nice code. Your answer is off to a good start. Please consider explaining how and why this code solves the problem so others can learn from it. Check the guide to answers for further advice. – Matthew Brown aka Lord Matt Sep 2 '19 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.