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.

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


 

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.

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.

Leave a Comment