Home » how to upload images in wordpress by custom code?

how to upload images in wordpress by custom code?

Today, We want to share with you image upload custom code in wordpress.In this post we will show you wordpress frontend user image upload, hear for how to upload image in wordpress using php we will give you demo and example for implement.In this post, we will learn about custom media uploader wordpress (PHP Upload File Size Limit) with an example.

Read Also:  AngularJS Parsing JSON data RESTful JSON Parsing

Image upload custom code in wordpress

There are the Following The simple About upload image in wordpress plugin code Full Information With Example and source code.

As I will cover this Post with live Working example to develop image upload in wordpress, so the create custom field and upload image in wordpress is used for this example is following below.

Custom Image Upload in WordPress

in wp_enqueue_scripts hook.

dd_action( 'wp_enqueue_scripts', 'enqueue_scripts_trigger' );
function enqueue_scripts_trigger() {
    wp_enqueue_media();
    wp_enqueue_script( 'my_custom_js', 'YOUR_JS_FILE_PATH', array( 'jquery' ), '1.0', true );
}

HTML Code

<input type="button" value="Upload Profile Image" class="button-primary" id="upload_image"/>
<input type="hidden" name="attachment_id" class="wp_attachment_id" value="" /> </br>
<img src="" class="image" style="display:none;margin-top:10px;"/>

custom js

(function( $ ) {
	'use strict';

	$(function() {
		
		$('#upload_image').click(open_custom_media_window);

		function open_custom_media_window() {
			if (this.window === undefined) {
				this.window = wp.media({
					title: 'Insert Profile Image',
					library: {type: 'image'},
					multiple: false,
					button: {text: 'Insert Profile Image'}
				});

				var self = this;
				this.window.on('select', function() {
					var response = self.window.state().get('selection').first().toJSON();

					$('.wp_attachment_id').val(response.id);
					$('.image').attr('src', response.sizes.thumbnail.url);
                                        $('.image').show();
				});
			}

			this.window.open();
			return false;
		}
	});
})( jQuery );

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Read Also:  Nullable Types in C#.NET With C# Nullables Example

I hope you get an idea about image upload custom code in wordpress.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  breadcrumb navxt shortcode
  2. Read Also:  Jquery Live Search Filter Example with Demo
  3. Read Also:  Angular Add & Get Custom Attribute Value
  4. Read Also:  Handling Arrays using jQuery Tutorial with Examples
  5. Read Also:  Ajax Upload Multiple Images without form submitting
  6. Read Also:  Free Google Syntax Highlighter in wordpress
  7. Read Also:  How to Get selected/checked Radio Button value using jQuery?
  8. Read Also:  how to delete (splice) an element from nested JSON using Vuejs
  9. Read Also:  Handling Arrays using jQuery Tutorial with Examples
  10. Read Also:  Nullable Types in C#.NET With C# Nullables Example

Leave a Comment

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