admin管理员组

文章数量:1289582

We have few WordPress sites with custom themes where new posts are added very frequently (more than 200 posts a day) so we are trying to be as efficient as possible. I tried to google for a solution but could not find an answer on this topic.

When the Post author clicks on Set Featured Image we want them to directly show them the Feature image uploader window since 99% of the time, we have different feature images for each post.

We have few WordPress sites with custom themes where new posts are added very frequently (more than 200 posts a day) so we are trying to be as efficient as possible. I tried to google for a solution but could not find an answer on this topic.

When the Post author clicks on Set Featured Image we want them to directly show them the Feature image uploader window since 99% of the time, we have different feature images for each post.

Share Improve this question asked Jun 30, 2021 at 23:40 Sahriar SaikatSahriar Saikat 1662 silver badges16 bronze badges 4
  • Please edit your question to include any code samples you've tried, even if they didn't work. As currently written, this question doesn't fit well in a WordPress development Q&A site. – Pat J Commented Jul 1, 2021 at 0:56
  • @PatJ As I mentioned in my post, I could not find any code sample or any other related discussion while Googling. All the results are about beginner tutorials about "How to set feature image". – Sahriar Saikat Commented Jul 2, 2021 at 0:07
  • Custom bookmarklets javascript:!function(){...code that clicks on buttons/links and makes some checks...}(); can sometimes do quick & dirty wonders with e.g. custom shortcut keys browser extensions :-) – birgire Commented Jul 5, 2021 at 15:18
  • @birgire We have few staffs working remotely. It may work for individuals but not for mid/large scale. – Sahriar Saikat Commented Jul 6, 2021 at 7:30
Add a comment  | 

1 Answer 1

Reset to default 2 +50

WordPress exposes media upload component globally, as well the featured image modal with wp.media.featuredImage so developers can interact with it.

FeaturedImage component uses the wp.media.frame which is a Backbone component, which has custom event attached to it.

There's not much documentation on it, you can check the source here.

You can use the following snippet to achieve your needs. It's uses the open event on media frame and set's content mode to upload, the default mode is browse.

function wpse_391259_init_featured_uploader_tab() {
    $script = <<<JSS
    (function (){
        var frame = wp.media.featuredImage.frame();
        frame.on( 'open',function() {
            frame.content.mode('upload')
        });
    })();
JSS;

    wp_add_inline_script( 'media-editor', $script );
}

add_action( 'wp_enqueue_media', 'wpse_391259_init_featured_uploader_tab' );

本文标签: post thumbnailsHow do I set quotUpload Imagequot as detault quotSet Featured Imagequot window