There’re 2 things you should consider:
-
change
send_to_editor
insideclick
callback. This will change this function only when needed, e.g. when uploader is shown. This also prevent unwanted things with global variables. -
You should always backup the
send_to_editor
.
Here’s my sample code (not tested):
jQuery(document).ready(function($) {
$('#upload_image_button_main').click(function() {
var backup = window.send_to_editor;
window.send_to_editor = function(html) {
imgurl = $('img', html).attr('src');
jQuery('#_my_meta_upload_image_main').val(imgurl);
tb_remove();
};
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
window.send_to_editor = backup;
return false;
});
});
Related Posts:
- Add “upload media” button in meta box field
- Add a Meta Box for uploading a SECOND Featured Image?
- Attach Files Metabox
- Adding uploaded images to editor from metabox instead of default popup uploader
- I need a Simple image uploader with a simple screen. WP default has too many options.
- Customize WordPress Media Upload and New Media Manager Menu in add post Metabox
- WPAlchemy MediaAccess inserting media link in WP Editor instead of custom field in metabox [closed]
- How to add meta box for image upload using WordPress media uploader?
- Insert media button will always add into the same tinyMCE editor
- Generating image sizes when uploading through wp.media
- Saving an upload media meta box field
- Create more Meta Boxes as needed
- Set Default Admin Screen options & Metabox Order
- How to set default screen options?
- Passing error/warning messages from a meta box to “admin_notices”
- Does WordPress have a “Form API”?
- Metabox with checkbox is not updating
- How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button
- What is the “Advanced” $context in add_meta_box?
- Removing panels (meta boxes) in the Block Editor
- Change The Title Of a Meta Box
- WordPress SEO by Yoast: Hide Meta Boxes in Posts for Non-admins
- How to make open/closed and hidden/shown metaboxes status saved on a per-post basis?
- How To Remove The “+ Add New Category” Link From A Category Metabox
- How can I create a taxonomy meta-box with search suggestions but no new terms input?
- Remove the Featured Image Meta Box
- Remove the Yoast SEO Post Metabox [closed]
- Best practices for meta box placement?
- Creating a metabox to upload multiple images
- How Does WordPress Remember Metabox Positions?
- Sample code for validating custom metabox?
- Post custom metabox textarea using wp_editor
- How to Add Reminders/Notes to New Post Meta Boxes
- How do I get attachment_id?
- Removing Metabox for “Slug” without removing functionality
- How to reorder meta box position?
- Prevent sorting and dragging of specific postbox metabox
- One metabox for multiple post types
- How do I position meta_box on post edit screen after the title?
- How to add a class to meta box
- Has anyone successfully integrated qtranslate with custom metaboxes?
- Put the media uploader in a metabox
- Custom Meta Boxes: multiple fields within a repeatable field
- Removing meta boxes: remove-meta_box() or unset()?
- Upload multiple images in a custom metabox
- Save checkbox value in metabox
- How to group meta boxes on the post edit page
- Use meta box drag and drop to order items independently
- inside a metabox
- Add Meta box Befoure Post Title
- Hiding a theme’s meta box
- Metabox date month number to word
- get registered metaboxes by post type or post ID
- Remove metabox from specific page template in admin
- Is there a filter/action to add content to WP admin metaboxes?
- CMB2 metabox conditional logic
- Adding upload button in metabox
- Using media-upload.php to upload mp3 via custom fields
- Tinymce/WordPress is removing all line-breaks?
- How do I create a meta box for dates?
- Adding submit or update button to custom metabox?
- Editing the Default Links like “Site Admin” in the Sidebar Meta Section?
- How to pass variable via $callback_args for add_meta_box
- Add metabox with media uploader in a custom post type [duplicate]
- Undefined function error when creating Custom Meta Box
- How to get meta box data to display on a page
- esc before saving or before displaying does it matter?
- Block metabox – No expanding, no moving around
- Remove tabs from media uploader for a CPT
- Move excerpt to always be directly below post content in admin
- Access the environment of an admin page from another admin page
- Add a meta description to home page?
- Editing Screen: Make Update or Publish Button Follow The Page
- Removing custom meta box added in parent theme
- Add filter ‘wpautop’ to meta box textarea
- Use meta box value in CPT as post title
- Custom “Publish” / “Update” button &
- Why can’t I hook into save_posts after admin_init?
- Meta Boxes in Front End Post Submission Form
- Getting the ID of a meta box
- how to sanitize checkbox input?
- add_meta_box does not go ‘side’
- Custom filter for the_content doesn’t work correctly
- Remove a plugin meta box from the dashboard
- How to insert Gallery shortcode to a meta box
- Getting jQuery sortable items in custom metabox
- Custom meta box shown when template is chosen [duplicate]
- Modifying the main editor priority
- How to make a meta box field a requirement
- Check if meta key value already exists
- How to make multicheck for post/page meta box
- Display list of tags as drop down menu or radio buttons in a meta box?
- How do I stop HTML entities in a custom meta box from being un-htmlentitied?
- Is there a predefined callback function for custom categories?
- Choosing a default page tempate (Classic => Gutenberg)
- meta content on required pages
- How to List all Sidebars in a Metabox
- How to remove the RichText Meta Box
- Set height of the categories meta box in post dashboard
- Conditional Meta Boxes