当前位置:首页>网络教程>站长教程>如何在WordPress后台页面添加上传按钮?

如何在WordPress后台页面添加上传按钮?

我们在进行WordPress主题开发过程中经常会遇到在后台某个页面添加上传按钮,那么如何在WordPress后台页面添加上传按钮?你需 ...

我们在进行WordPress主题开发过程中经常会遇到在后台某个页面添加上传按钮,那么如何在WordPress后台页面添加上传按钮?你需要用到wp_enqueue_media()这个函数,用于引入上传所需组件。

如何在WordPress后台页面添加上传按钮?

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;

});

}

}

});

给TA打赏
共{{data.count}}人
人已打赏
站长教程网络教程

WordPress网站侧边栏添加悬浮分享按钮教程

2022-7-15 17:11:39

站长教程网络教程

如何在WordPress 后台菜单添加气泡通知?

2022-7-15 17:11:58

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索