加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > 正文

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

发布时间:2020-05-30 03:04:47 所属栏目:CMS系统 来源:互联网
导读:如果你需要在后台某个页面添加上传按钮,你需要用到wp_enqueue_media()这个函数,用于引入上传所需组件。

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。脚本之家小编现在分享给大家,也给大家做个参考。

如果你需要在后台某个页面添加上传按钮,你需要用到 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;

});

}

}

});

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读