JavaScript Wordpress - Uncaught TypeError: wp.media is not a function wordpress uncaught typeerror $ is not a function,wordpress uncaught typeerror

I want my users to be able to upload images to my website. They don't have to be logged in.

I have a custom Page template where I would like to perform this. And I have the following chunk of code inside my functions.php

wp_deregister_script('jquery');
wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js', false, '1.11.3');
....
---------more codes are here---------
....
else if( in_category( $excluded, get_the_ID() ) || get_page_template_slug() == 'mediaCollector.php') {
    wp_enqueue_media();
    wp_enqueue_style('media_collector', get_stylesheet_directory_uri() . '/mediaCollector.css');
    wp_enqueue_style('style_responsive', get_stylesheet_directory_uri() . '/style-responsive.css');
    wp_enqueue_style('font-awesome', plugins_url() . '/my-plugin/css/font-awesome.min.css');

    wp_enqueue_script('mediaCollectorScript', get_stylesheet_directory_uri() . '/mediaCollector.js');
}
....
---------more codes are here---------
....

This is the code for what happens when the Upload image button is clicked (which opens the popup where user can upload media).

    \$j = jQuery.noConflict();

    /* Logo Upload */
    \$j(document).ready(function() {
        \$j('.upload-btn').click(function(a) {
            var that = this;
        a.preventDefault();
        var b = wp.media({
            title: 'Upload Image',
            multiple: !1
        }).open().on('select', function(a) {
            var c = b.state().get('selection').first();
            var d = c.toJSON().url;
            \$j(that).parent().find('input[type=text]').val(d)
        });
    });

But I am getting the following error on clicking the Upload button.

Uncaught TypeError: wp.media is not a function

Am I missing something? Any help is appreciated.

Answer:1

I need to get the HTML of the whole page, with the current values of all inputs in their value="...". I've tried this: document.getElementById("htmlId").innerHTML; and this: $('html').html(); but ...

I need to get the HTML of the whole page, with the current values of all inputs in their value="...". I've tried this: document.getElementById("htmlId").innerHTML; and this: $('html').html(); but ...

  1. jquery html with current element
  2. html copyright with current year
  3. html input with current date
  4. html current date
  5. html current year
  6. html current time
  7. html current version
  8. html current url
  9. html current date and time
  10. html current timestamp
  11. html current
  12. html current directory
  13. html current year footer
  14. html current month
  15. html current date and time display
  16. html current path
  17. html current location
  18. html current page
  19. html current page url
  20. html current datetime

import Request from 'superagent'; const getApi = () => { let url = '/* URL */'; return Request.get(url).then((res) => { this.setState({ content: res.body });...

import Request from 'superagent'; const getApi = () => { let url = '/* URL */'; return Request.get(url).then((res) => { this.setState({ content: res.body });...

  1. setstate in external function
  2. react setstate from external function

With the help of the following code i am able to embed google search bar within my website <iframe id="if1" width="100%" height="254" style="visibility:visible" src="http://www.google.com/custom?q=...

With the help of the following code i am able to embed google search bar within my website <iframe id="if1" width="100%" height="254" style="visibility:visible" src="http://www.google.com/custom?q=...

I want to add the Shipping and Billing addresses form in the cart.liquid file so it is possible to add these two addresses form in cart page if anybody known then give solution for this.

I want to add the Shipping and Billing addresses form in the cart.liquid file so it is possible to add these two addresses form in cart page if anybody known then give solution for this.

  1. shipping billing addresses
  2. shipping billing address difference
  3. billing/shipping address mismatch
  4. billing shipping address javascript
  5. shipping address billing paypal
  6. billing shipping address form
  7. shipping address billing address
  8. shipping address billing information
  9. shipping vs billing address
  10. shipping and billing address don't match
  11. shipping and billing address in amazon
  12. shipping and billing address lazada
  13. shipping and billing address meaning
  14. shipping and billing address must match
  15. supreme shipping billing address
  16. amazon shipping billing address different
  17. drop shipping billing address
  18. shipping cart billing address
  19. ebay shipping billing address different
  20. shipping and billing address in gst