13

How can get a modal window to work from within the wordpress admin?

I want to create a modal window that will work from a meta box within the wp-admin.

Any ideas?

  • 2
    50% is pretty low - please remember to return to your old questions and accept correct answers. It takes them off the 'unanswered' pile and helps others find solutions more easily. People will also be more willing to offer answers if they know that the OP will respond to them. :) – Stephen Harris Apr 10 '12 at 15:47
16

Give the anchor a class of thickbox and make sure that the thickbox script is enqueued on your admin page using add_thickbox

add_thickbox();

and

<a href="your url" class="thickbox">click here</a>

You can see what add_thickbox does here:

http://hitchhackerguide.com/2011/02/11/add_thickbox/

  • 2
    I think it might not be necessary to enqueue thickbox: it is automatically (at least in some instances) enqueued on a post edit page. See add_thickbox() too. – Stephen Harris Apr 10 '12 at 16:05
  • So how would I populate it with html? – Shae Apr 10 '12 at 17:41
  • Note your url, it loads the URL of the anchor into an iframe – Tom J Nowell Apr 10 '12 at 18:48
  • 1
    I just spent 40 minutes exporting modal only bootstrap css and JS and getting it into the dashboard -_-. Could have spent 30 seconds doing this... – Archonic Apr 29 '15 at 18:06
25

To use Thickbox for inline modal windows you can use the following code.

<?php add_thickbox(); ?>

<a href="#TB_inline?width=600&height=550&inlineId=modal-window-id" class="thickbox">Modal Me</a>

<div id="modal-window-id" style="display:none;">
    <p>Lorem Ipsum sit dolla amet.</p>
</div>

http://codex.wordpress.org/ThickBox

  • 1
    Also, It is possible to set a modal window title by adding title attribute to link or button. <a href="YOUR LINK" title="MODAL WINDOW TITLE" class="thickbox">Modal Me</a> – anton May 20 '18 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.