WordPress后台页面里添加上传按钮
以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考 如果你需要在后台某个页面添加上传按钮,你需要用到 wp_enqueue_media()这个函数,用于引入上传所需组件。 add_action ( 'admin_enqueue_scripts',function () { if (is_admin ()) wp_enqueue_media (); } ); html 代码:<p> <input type="number" value="" class="regular-text process_custom_images" id="process_custom_images" name="" max="" min="1" step="1"> <button class="set_custom_images button">Set Image ID</button> </p> js 代码:jQuery(document).ready(function() { var $ = jQuery; if ($('.set_custom_images').length > 0) { if ( typeof wp !== 'undefined' && wp.media && wp.media.editor) { $(document).on('click','.set_custom_images',function(e) { e.preventDefault(); var button = $(this); var id = button.prev(); wp.media.editor.send.attachment = function(props,attachment) { id.val(attachment.url); }; wp.media.editor.open(button); return false; }); } } }); 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |