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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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' );
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0
