admin管理员组文章数量:1122846
I was wondering if there's a hook/function to add a new tab to the Featured image modal window as shows in the picture below:
I've found this thread How to add new tab to media upload manager with custom set of images?, but the answers from there didn't work for me.
I was wondering if there's a hook/function to add a new tab to the Featured image modal window as shows in the picture below:
I've found this thread How to add new tab to media upload manager with custom set of images?, but the answers from there didn't work for me.
Share Improve this question asked Aug 12, 2024 at 18:24 mikebrsvmikebrsv 1011 Answer
Reset to default 2WordPress does not have a built-in hook or function on the PHP side that allows you to directly add a new tab to the Media Library Modal window. To achieve this, you need to use JavaScript to modify the media uploader interface.
You can add a custom tab to the WordPress Media Library modal by using JavaScript to extend the media frame. Here’s a quick example:
JavaScript Code:
jQuery(document).ready(function($){
var originalMediaTabs = wp.media.view.MediaFrame.Select.prototype.browseRouter;
wp.media.view.MediaFrame.Select.prototype.browseRouter = function(routerView) {
originalMediaTabs.apply(this, [routerView]);
routerView.set({
'new-tab': {
text: 'New Tab', // Tab title
priority: 100
}
});
};
wp.media.view.MediaFrame.Select.prototype.on('router:new-tab', function() {
this.content.set(new wp.media.view.AttachmentsBrowser({
controller: this,
collection: new wp.media.model.Attachments(),
selection: this.state().get('selection'),
model: this.state()
}));
});
});
PHP Code:
function my_custom_media_scripts() {
wp_enqueue_script(
'my-custom-media-scripts',
plugin_dir_url(__FILE__) . 'js/admin.js', // Path to your JS file
array('jquery', 'media-views'), // Dependencies
null,
true
);
}
add_action('admin_enqueue_scripts', 'my_custom_media_scripts');
This JavaScript code adds a new tab called "New Tab" to the Media Library modal window. The PHP code enqueues the JavaScript on admin pages.
本文标签: uploadsFeatured Image add tab
版权声明:本文标题:uploads - Featured Image add tab 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298120a1930160.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论