You need to call wp_enqueue_media() else the wp object won’t have a media option.
For example, go to WP Admin and pull up the JS console and type wp.media on the dashboard, it won’t work. Try again on the media page, and this time it will work.
https://codex.wordpress.org/Javascript_Reference/wp.media
To be able to use the JavaScript-API, you first have to init all the needed JavaScript-Libraries and Styles:
wp_enqueue_media();
Related Posts:
- show hide image script after 4 seconds [closed]
- Set default image link target in Gutenberg image block
- Graphing libraries for WordPress [closed]
- 3.5 media.editor: what is the event listener for choosing an image?
- JavaScript and images files are not recognized
- Update an image block style programatically
- Howto use WP built in Thickbox for images?
- Image modification
- Landing Page with HTML CSS JS and Images on wordpress
- Built-in image lazy loading: Does it come with a polyfill for older browsers?
- Images names not inserting in WordPress Database from Dynamic Add / Remove fields
- js alert in add_filter function for image_send_to_editor
- Display images from JS?
- 3.5.x Theme Customize: Handling Custom Control Requests
- Script not working in WordPress [duplicate]
- Getting Images from theme’s directory in pages
- Img Src File path issue
- Images dont show in grid view, but do in list view
- Replace all of post’s image URLs with upload directory URLs
- Restrict the number of images to upload per post
- How to display a shortcode caption somewhere other than the_content
- Wrap all post images inside a div element
- Get total number of pixels, size in megapixels and aspect ratio based on image width and height?
- How to link Gutenberg Gallery images To Media file automatically?
- Did I do it right? Deleting images after deleting product. Woocommerce
- When displaying the featured image, is has_post_thumbnail() necessary?
- Uploading images to Media Library fails with Memory Exhausted
- unable to upload image locally
- Edit image preview is not displayed
- get attributes/part of the gallery shortcode
- extract post image to be featured images
- Sidebar slideshow widget [closed]
- Image file sizes increasing on upload
- How to set a Minimum Image Dimension for Uploading
- get_attachment_id() only get id of first attached image after post update
- Different upload path per file type
- Custom page template to display all image attachments
- HTML tags in WordPress image caption
- Using Add_image_size when adding image in post
- Creating page templates with image placeholders
- how to attach an image to a custom post type in wordpress using just code
- How can I upload an image for background use using the Theme Editor in WordPress?
- Where are the resized images coming from?
- unattached media files that should be attached
- Site migration – some images not displaying in Media Library
- can you call the alt tag for an image dynamically?
- Migration to WP – Couldn’t load image
- Multiple amp-image overlays. How to properly do this in wordpress?
- add media button is not working
- Undefined index: sui_image_caption in [closed]
- Replacing the content of an image attachment using API
- User-uploaded images without an account
- fetch images and videos
- Specific image size is being generated without being registered
- Should I not compress my jpeg files before uploading to avoid double compression?
- Generating a certain sized thumbnail on the fly?
- How to display title of attached image in post?
- Getting thumbnail of uploaded image
- Display image for first sticky post only
- Get all image IDs from the Media Library
- Link listings with image
- Allow users to contribute images to a post
- Can’t add image to site via php
- After Migration, images show up on a preview of the page but not the actual page [closed]
- Save Image in wp_options-Table
- Image upload error?
- Is it possible to get feature image url (full-size) from an image url of smaller size?
- How to pass on a value as parameter via url to another page
- Image not showing using a custom function and get_post_meta
- Random home page background images with caption text
- How to add “alt” attribute for image during upload at WP front-end?
- Get Original Dimension Featured Image on the homepage
- WordPress keeps resizing my 947×947 image down to 500×500 (full-size option)
- Excluding post thumbnail from the attachment.php when using wordpress gallery
- Featured Image Thumbnail size on Twenty Ten Archive Page
- attach several images to post + gallery
- Widget Style – Icon Type
- WordPress Problems
- Pictures randomly replaced by blue question mark
- WordPress PHP custom function is causing 500 Internal Server Error Connection Timeout
- Post-processing of the image failed
- Get post thumbnail in specific size
- Text not wrapping properly around image in WordPress Visual Editor [closed]
- Why do images inserted in the post content via the_content() go off the max-width?
- Image automatically resized
- Theme page headers and rotator images not assigned after website migration
- Images Wont Display After Importing From Old WordPress
- Image thumbnail on single product issue | WooCommerce
- How can I hook and edit on the fly an image uploaded
- Anomaly with response coming from XML RPC Api get Post (integer out of range)
- Make all images displayed in single.php a certain size
- Create a custom attachment thumbnail for quick page load
- Change the image for a certain URL
- Removing image dimensions from `the_content`
- Multiple gallery thumnbnails on one page
- Change image link in excerpt to point to post
- Putting the title attribute in image tag — Snapshot Theme from Woothemes
- Post migration – images do not display
- wp_handle_upload Image sizes
- Display Images from Array with wp_get_attachment_image() [closed]