This is a short tutorial on extending the WordPress media modal with your own content. Here we add a button in the media upload image details section.
The wp.media class
When adding, choosing and editing images in WordPress, most of the time you will see a modal opening up. This can be for the upload, selecting an image from within a post, or checking image details in the media library. Each of these modals is part of wp.media
in the wp scope/namespace.
According to the documentation “wp.media
is used to handle and control the admin media modal. For instance, custom image selector/uploader controls and meta boxes.”
Adding buttons to the modals
If you try extending the WordPress media modal with your own plugin or theme content, you best use JavaScript. I found a way that works for me. There may be other options, but I will describe how I added custom buttons to WordPress image details.
In this example, I will add a button after the main image details in the upload modal.

1) Finding the correct template
The most important detail to extend anything is to know where exactly you are trying to change content. In the beginning, it took me a while to find the correct templates. In the end I reverted to not searching the wp.media class itself, but to check in the developer console in my browser.
First, I check the class names within the modal itself. Usually the one before a headline is correct. But it doesn’t hurt to remember a view of them.

Then I look for the template scripts in the beginning of #wpcontent
. There should be one which has the name of the just found classname. You can also find it by searching for some of the text within that template. Here for example, you could look for “Delete permanently” and you will find exactly those words in the script. (This means, you can also switch the order of those steps. You should just make sure the template class name is also available in your modal content.)

Then I check this resource: https://atimmer.github.io/wordpress-jsdoc/ It has all the needed docs and references.
Within the main navigation “classes” you should find your template for wp.media.view.XXX. My class is tmpl-attachement-details –> so I am searching for wp.media.view.Attachment.Details

In there jump straight to the source and make sure there is a template I can extend:

I know, I am already sure there is a template due to the tmpl script. But it doesn’t hurt to make sure.
And now I can finally get into the view itself and can start writing the code.
2) Extending the template
In my JavaScript, I call and extend the found class with my new template content:
wp.media.view.Attachment.Details = wp.media.view.Attachment.Details.extend({
template: function(view) {
// tmpl-attachment-details
const html = wp.media.template('attachment-details')(view); // the template to extend
const dom = document.createElement('div');
dom.innerHTML = html;
// create image actions wrapper
const details = dom.querySelector('.details');
const actions = document.createElement('button'); // create new element
actions.classList.add('anna-edit-button'); // add a class to the element for styling
actions.setAttribute('id', this.model.attribute.id); // add the image-id using the attributes
actions.innerHTML = 'Edit image'; // element text
details.appendChild(actions); // add new element at the correct spot
return dom.innerHTML;
}
});
Now the template will include my button. (For the styling, you have to include your own CSS. This is not part of this description.)As we are within the class Attachment.Details, we can access all image attributes in our code. As an example, I used attribute.id
for the button id. You can also use the image url, etc.
2.1 ) Adding click listeners
For now, the button looks nice and is at the right spot, but it doesn’t help much if it’s not clickable. The templates all have events and we need add our own listeners and actions.
wp.media.view.Attachment.Details = wp.media.view.Attachment.Details.extend({
events = {
...wp.media.view.Attachment.Details.prototype.events, // keep all existing events
'click .anna-edit-button' : 'photiniaEditAttachment', // add our own click listener
}
template: function(view) {
...
}
});
2.2 ) Adding the listener method
And finally, I need the method called in my event listener. In this example I will trigger a console.log and a re-render. The re-render makes most sense if you actually edited the image. But maybe that’s what you want to do.
wp.media.view.Attachment.Details = wp.media.view.Attachment.Details.extend({
photiniaEditAttachment: function(e)
{
const { id } = this.model.attributes;
console.log( id )
this.model.fetch({
success: () => {
this.render();
},
error: (collection, response, options) => {
console.log('error fetching view model');
}
});
},
events = {
...
}
template: function(view) {
...
}
});
That’s it. Now we added a button to the upload modal AttachmentDetails section and made that button clickable.
I hope this helps to create other template extensions and elements.
This doesn’t seem to work with WP 6.5 anymore.
You’ve made some really good points there. I checked on the internet for additional information about the issue and found most individuals will go along with
your views on this site.
I don’t even know how I stopped up here, however I thought this post used to be good.
I do not understand who you are but certainly you
are going to a famous blogger if you aren’t already.
Cheers!
Pretty nice post. I simply stumbled upon your blog and wanted to say that I’ve truly enjoyed
surfing around your weblog posts. In any case I’ll be subscribing in your feed and I’m hoping
you write once more very soon!
I will immediately seize your rss as I can not in finding your e-mail subscription link or e-newsletter
service. Do you have any? Kindly let me know so
that I may just subscribe. Thanks.
My partner and I absolutely love your blog and find most of your post’s to be precisely
what I’m looking for. can you offer guest writers to write content available for you?
I wouldn’t mind creating a post or elaborating on most of the subjects you write in relation to here.
Again, awesome web log!
of course like your website but you have to check the
spelling on several of your posts. A number of
them are rife with spelling issues and I find it very bothersome to tell the
truth then again I’ll surely come again again.
Incredible points. Outstanding arguments. Keep up the great work.
If some one wishes to be updated with most recent technologies after that
he must be visit this web page and be up to date everyday.
Hello there! I could have sworn I’ve been to this web site before but after browsing through some of the articles I realized it’s
new to me. Nonetheless, I’m definitely delighted
I stumbled upon it and I’ll be bookmarking it and checking back regularly!
If you wish for to obtain a great deal from this paragraph then you have to
apply these techniques to your won blog.
Geniet van eineeloos entertainment met IPTV Smarters Рro op Flixion. Compatibel met ɑlle slimme apparaten voor
moeiteloze entertainment. Begjn vandaag noց met kijken!
Zoek je ԁe eѕte manier om IPTV tе kopen? Kies voor Flixion voor ⅾe ultieme IPTV ervaring.
Geniet ѵɑn HD live tv-kanalen еn meer opp elk
slim apparaat mеt onzee service.
Heeb je genoeg vaan traditionele tv? Probeer IPTV Smarters Ρro voor onbeperkte streamingmogelijkheden, allsmaal mmet Flixion. Bekijk Ԁe optis vandaag noɡ!
Vind uit hoе IPTV Smarters Pro Ьij Flixion je tv-kijkervaring кan transformeren. Stream live
kanalen еn HD-inhoud moeiteloos op аl je apparaten. Veerhoog ԁe kwaliteit ѵan je tv-ervaring vandaag nog!
Bеn je op zoek naar de perfecte IPTV-oplossing?
Probeer Smart IPTV mеt Flixion en ervaar hhet verschil іn kwaliteit.
Onze diensten zijn ontworpen voor jouw gemak.
Hi, all is going sound here and ofcourse every one
is sharing facts, that’s in fact fine, keep up writing.
Have you ever considered writing an ebook or guest
authoring on other sites? I have a blog based upon on the same topics you discuss and would love
to have you share some stories/information. I know my subscribers would appreciate your work.
If you’re even remotely interested, feel free to send me an e mail.
Hello There. I discovered your blog the usage of msn. That is a
very neatly written article. I’ll make sure to bookmark it and
come back to learn extra of your useful info. Thanks for the post.
I will definitely return.
I’m not sure why but this site is loading incredibly slow for
me. Is anyone else having this problem or is it a problem
on my end? I’ll check back later on and see if the problem still exists.
This article offers clear idea in favor of the
new viewers of blogging, that really how to do running a blog.
If you would like to increase your know-how just keep visiting this site and be
updated with the most recent gossip posted here.
E2Bet Indonesia, situs judi online terbesar di Indonesia, aman, terpercaya,
dan inovatif, bonus menarik dan layanan pelanggan 24/7. #E2Bet #E2BetIndonesia #Indonesia
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you! However, how can we communicate?
It’s remarkable to visit this website and reading the views of all
mates on the topic of this piece of writing, while I am also zealous
of getting knowledge.
Wow! After all I got a webpage from where I be able to truly
obtain helpful information regarding my study and knowledge.
Way cool! Some very valid points! I appreciate you writing this write-up and the rest
of the site is also very good.
I take pleasure in, cause I found exactly what I used to be having
a look for. You’ve ended my four day lengthy hunt!
God Bless you man. Have a nice day. Bye
Inspiring story there. What happened after? Thanks!
Heya! I realize this is somewhat off-topic however I needed to
ask. Does operating a well-established website such as yours take a massive amount work?
I am brand new to writing a blog but I do write in my
diary every day. I’d like to start a blog so I can share my
experience and feelings online. Please let me know
if you have any suggestions or tips for new aspiring blog owners.
Thankyou!
If you are going for finest contents like I
do, just pay a visit this web page everyday since it offers quality contents, thanks
Hello. . [url=https://don-rem.ru]don-rem.ru[/url]
https://don-rem.ru
https://don-rem.ru zwz4967494
I’m gone to inform my little brother, that he should also pay a visit this website on regular basis to obtain updated from latest reports.
Hi there, Yoou have done an incredible job. I’ll definitely digg itt
andd personally suggest to my friends. I am confident they’ll be
benefited from this web site.
Hi, Neat post. There’s an issue with your web site in web
explorer, may test this? IE still is the market leader and
a large component of other people will omit your fantastic writing due to this problem.
Hello there, just became aware of your blog through Google, and found
that it is truly informative. I’m going to watch out for brussels.
I will be grateful if you continue this in future. Many people
will be benefited from your writing. Cheers!
I believe what you said made a bunch of sense.
However, consider this, suppose you composed a catchier title?
I mean, I don’t wish to tell you how to run your website, however suppose
you added a title that makes people desire more? I mean Adding custom content to WordPress media modals – Anna Schneider is
kinda boring. You ought to peek at Yahoo’s front page and see how they create news titles to grab people interested.
You might try adding a video or a related picture or two to get people interested about what you’ve written.
Just my opinion, it might make your website a little livelier.
Attractive component of content. I just stumbled
upon your website and in accession capital to say that I acquire actually
loved account your blog posts. Any way I will be subscribing to your augment or even I success you get right of entry to
persistently quickly.
Way cool! Some extremely valid points! I appreciate you
penning this write-up and the rest of the site is also very good.
You actually make it seem so easy with your presentation but I find
this matter to be really something that I think I’d by no means understand.
It sort of feels too complex and extremely extensive
for me. I’m looking ahead for your next post, I
will attempt to get the hold of it!
Hi there! I know this is somewhat off topic but I was wondering which blog
platform are you using for this site? I’m getting tired of WordPress because I’ve had problems
with hackers and I’m looking at alternatives for another platform.
I would be awesome if you could point me in the direction of a good platform.
I am genuinely grateful to the holder of this website who has
shared this great paragraph at at this time.
I do not even understand how I stopped up right here, however I believed this put
up was once good. I don’t realize who you are however definitely you’re going to a well-known blogger in case you aren’t already.
Cheers!
fantastic points altogether, you simply gained a new reader.
What might you recommend in regards to your post that you simply made a few
days ago? Any sure?
Heya! I realize this is kind of off-topic however I needed to ask.
Does operating a well-established blog such as yours take a massive amount work?
I am completely new to blogging however I do write in my diary on a daily basis.
I’d like to start a blog so I can easily share my personal experience and feelings online.
Please let me know if you have any ideas or tips for new aspiring blog owners.
Appreciate it!
Please let me know if you’re looking for a author for your weblog.
You have some really good posts and I feel I would be a good asset.
If you ever want to take some of the load off, I’d really like to write
some content for your blog in exchange for a link back to mine.
Please shoot me an email if interested. Cheers!
It is not my first time to visit this website, i am browsing
this site dailly and obtain pleasant information from here all the time.
It’s truly very complicated in this busy life to listen news on Television, so I only use the web for that
reason, and obtain the most up-to-date information.
Thanks for a marvelous posting! I definitely enjoyed reading it, you may be a great author.
I will be sure to bookmark your blog and will come back someday.
I want to encourage you continue your great work,
have a nice holiday weekend!
certainly like your web site however you need to take a look at the spelling on several of your posts.
Many of them are rife with spelling problems and I in finding it very troublesome to inform the
truth then again I’ll definitely come back again.
Good blog you have got here.. It’s difficult to find high
quality writing like yours nowadays. I seriously appreciate people like you!
Take care!!
Right away I am going away to do my breakfast, when having my breakfast
coming again to read more news.
betfilx
Unquestionably believe that which you said.
Your favorite justification seemed to be on the net
the easiest thing to be aware of. I say to you, I certainly get annoyed while people
think about worries that they just don’t know about.
You managed to hit the nail upon the top as well as defined out the whole thing
without having side-effects , people can take a signal.
Will likely be back to get more. Thanks
Great items from you, man. I’ve consider your stuff previous to
and you’re just extremely magnificent. I actually like what you’ve bought here, certainly like
what you’re saying and the way through which you assert it.
You make it entertaining and you continue to care for to stay it sensible.
I can not wait to read much more from you. This is actually a great site.