0

I've added a Thickbox to an admin page by adding the the following action hook to add the library code

add_action( 'in_admin_footer', function(){   
    add_thickbox();    
});

And then triggering an inline thick box manually via some javascript code

tb_show(null,'#TB_inline?height=300&width=300&inlineId=id_of_div_with_my_thickbox',false);

When I do this, the thickbox has some margins/padding on the left and right (see in screenshot below how everything is centered)

enter image description here

I'd like to

  1. Remove these styles for everything is flush against the Thickbox (as a style reset)
  2. But only for my Thickbox.

Re: #2 -- This is something for a plugin that's going to be on many admin backend pages. I know I can target the id=TB_ajaxContent div to change the style -- but this runs the risk of breaking other Thickboxes added to the system

Is there known science for this in the Wordpress community? Or am I on my own as a plugin developer to create this functionality myself?

2
  • If the goal of this is to have a button that shows a modal with an autocomplete box, then why not improve your UX by just placing the autocomplete box inside the original UI rather than requiring a modal thickbox creating UX friction?
    – Tom J Nowell
    Commented Aug 7, 2016 at 22:16
  • @TomJNowell That's good UX advice, but that's not the goal. Commented Aug 7, 2016 at 23:10

1 Answer 1

0

You can use this for a custom stylesheet. Copy and paste all the CSS from the original thickbox.css in your custom stylesheet.

Now you can edit your custom CSS and add the code below in your plugin.

function get_thickbox() {
    // Add the original thickbox
    add_thickbox();

    // register your custom stylesheet
    // Make sure its in your speciefied folder!
    wp_register_style( 'thickbox_css', plugins_url( 'pluginname/stylesheet.css' ) );

    // enqueue our new stylesheet
    enqueue_style( 'thickbox_css' );
}
add_action('wp_enqueue_scripts', 'get_thickbox');

// Thats it!
// You can now reach your customized thickbox by:
get_thickbox();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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