WordPress教程

WordPress后台页面里添加上传按钮

阿里云

如果你需要在后台某个页面添加上传按钮,你需要用到 wp_enqueue_media()这个函数,用于引入上传所需组件。

  1. add_action ( 'admin_enqueue_scripts', function () {
  2. if (is_admin ())
  3. wp_enqueue_media ();
  4. } );
也想出现在这里?联系我们
创客主机

HTML 代码:

  1. <p>
  2. <input type="number" value="" class="regular-text process_custom_images" id="process_custom_images" name="" max="" min="1" step="1">
  3. <button class="set_custom_images button">Set Image ID</button>
  4. </p>

js 代码:

  1. jQuery(document).ready(function() {
  2. var $ = jQuery;
  3. if ($('.set_custom_images').length > 0) {
  4. if ( typeof wp !== 'undefined' && wp.media && wp.media.editor) {
  5. $(document).on('click', '.set_custom_images', function(e) {
  6. e.preventDefault();
  7. var button = $(this);
  8. var id = button.prev();
  9. wp.media.editor.send.attachment = function(props, attachment) {
  10. id.val(attachment.url);
  11. };
  12. wp.media.editor.open(button);
  13. return false;
  14. });
  15. }
  16. }
  17. });

WordPress 后台页面里添加上传按钮

已有 451 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!