AOW >> Media upload files button in wordpress
wordpress-category-image

Media upload files button in wordpress

Add the media upload files button in WordPress theme OR plugin is imperative because usually WordPress developers need this options for add OR use the data.

Add the media files buttWordPress is not very hard it is easy to add and use.

Steps For Add The Media Upload Files Button in WordPress

Steps For Add The Media Upload Files Button in WordPress

add media files button in WordPress, how add media files button, add WordPress media file button in the plugin, add media file button in theme, media file button in plugin and theme, media button, a complete tutorial, free tutorial

Add media files button in WordPress | how add media files button | add WordPress media file button in plugin | Add media file button theme.

For add the media upload files button follow the following  instructions:

  • Insert the following code in your WordPress script function.
wp_enqueue_script('jquery');
wp_enqueue_media();

 

  • After this, you need to add the following code where you want to show the button for upload/select the files.

 

<input type="text" name="image_url" id="image_url" class="regular-text" style="display:none;">

    <input type="button" name="upload-btn" id="upload-btn" class="button-secondary" value="Upload Image">
  • Insert the following code in the footer OR at the end of the function
<script type="text/javascript">
 jQuery(document).ready(function($){
  $('#upload-btn').click(function(e) {
 e.preventDefault();
 var image = wp.media({ 
 title: 'Upload Image',
 // mutiple: true if you want to upload multiple files at once
 multiple: false
 }).open()
 .on('select', function(e){
 // This will return the selected image from the Media Uploader, the result is an object
 var uploaded_image = image.state().get('selection').first();
 // We convert uploaded_image to a JSON object to make accessing it easier
 // Output to the console uploaded_image
 console.log(uploaded_image);
 var image_url = uploaded_image.toJSON().url;
 // Let's assign the url value to the input field
 $('#image_url').val(image_url);
  });
  });
  });
 </script>

 

  • Get the image link selected by the user from the media files of the WordPress by the following method
<?php $media_file_url=$_REQUEST[“image_url”];  ?>

Enjoy!!!!!!!

If you need further information, OR you want to discuss further things, please contact us! We like to hear from you,  and we are here for your help.

Thanks!

Likes(0)Dislikes(0)
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *


*