{"id":31072,"date":"2020-06-23T10:16:58","date_gmt":"2020-06-23T10:16:58","guid":{"rendered":"https:\/\/www.designbombs.com\/?p=31072"},"modified":"2020-06-26T08:30:06","modified_gmt":"2020-06-26T08:30:06","slug":"adding-modal-windows-in-the-wordpress-admin","status":"publish","type":"post","link":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/","title":{"rendered":"Adding Modal Windows in the WordPress Admin Without JavaScript"},"content":{"rendered":"<p>When creating a theme or plugin for WordPress which requires users to read some documentation, it is a good idea to display the documentation right within the WordPress admin. Otherwise, making the user browse an external site could produce a negative experience from the additional friction.<\/p>\n<p>I have written about <a href=\"https:\/\/css-tricks.com\/adding-a-custom-welcome-guide-to-the-wordpress-block-editor\/\">displaying documentation within Gutenberg<\/a>, which enables to make use of the available React-based components for different use cases. For instance, we can display our documentation by reusing the <code>&lt;Guide&gt;<\/code> component:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31082\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-welcome-guide.jpg\" alt=\"Gutenberg welcome guide\" width=\"1172\" height=\"876\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-welcome-guide.jpg 1172w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-welcome-guide-300x224.jpg 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-welcome-guide-1024x765.jpg 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-welcome-guide-768x574.jpg 768w\" sizes=\"auto, (max-width: 1172px) 100vw, 1172px\" \/><\/p>\n<p>However, what happens if we are not operating within Gutenberg? For instance, we may have coded our plugin long time ago, and migrating it to Gutenberg is too much of an effort. In that case, how could we manage to open a modal window in the WordPress admin?<\/p>\n<p>Unsurprisingly, we can reuse any functionality shipped anywhere by WordPress, not just through Gutenberg. And WordPress does already provide an implementation of a modal window, which is originally used to display plugin information:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31078\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-viewdetails.jpg\" alt=\"Modal window showing information about the plugin\" width=\"2560\" height=\"1228\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-viewdetails.jpg 2560w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-viewdetails-300x144.jpg 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-viewdetails-1024x491.jpg 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-viewdetails-768x368.jpg 768w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-viewdetails-1536x737.jpg 1536w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-viewdetails-2048x982.jpg 2048w\" sizes=\"auto, (max-width: 2560px) 100vw, 2560px\" \/><\/p>\n<p>Even though designed for plugins, the modal window can nevertheless display any arbitrary content, since it is simply an <code>iframe<\/code> embedding the intended page, for any page from the same domain. And opening the modal window can be triggered from anywhere within the WordPress admin, not just from within the plugins page.<\/p>\n<p>For instance, similar to the plugins page, our plugin could print a table with custom entries, and a &#8220;View details&#8221; link below each entry:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31080\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-list-with-link.png\" alt=\"A list with information from a custom plugin\" width=\"1428\" height=\"803\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-list-with-link.png 1428w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-list-with-link-300x169.png 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-list-with-link-1024x576.png 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-list-with-link-768x432.png 768w\" sizes=\"auto, (max-width: 1428px) 100vw, 1428px\" \/><\/p>\n<p>And when clicking on this link, it opens a modal window to display the entry&#8217;s corresponding documentation:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31081\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-modal-opened.png\" alt=\"Showing documentation from the custom plugin in a modal window\" width=\"1428\" height=\"803\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-modal-opened.png 1428w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-modal-opened-300x169.png 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-modal-opened-1024x576.png 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/wp-admin-modal-opened-768x432.png 768w\" sizes=\"auto, (max-width: 1428px) 100vw, 1428px\" \/><\/p>\n<p>In this article we will learn how to do this. The goal is to reuse the WordPress admin&#8217;s modal windows for our own themes or plugins, without depending on Gutenberg for this basic functionality.<\/p>\n<h2 id=\"loading-js-css-assets\">Loading the JS\/CSS assets<\/h2>\n<p>WordPress handles the modal windows through the following 3 files:<\/p>\n<p>File <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/master\/wp-includes\/js\/thickbox\/thickbox.js\"><code>wp-includes\/js\/thickbox\/thickbox.js<\/code><\/a> loads ThickBox, the library that provides the functionality for the modal window.<\/p>\n<p>File <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/master\/wp-includes\/js\/thickbox\/thickbox.css\"><code>wp-includes\/js\/thickbox\/thickbox.css<\/code><\/a> gives the styles for the modal window, including its placement on the page, and transitions when opening\/closing the modal.<\/p>\n<p>File <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/master\/wp-admin\/js\/plugin-install.js\"><code>wp-admin\/js\/plugin-install.js<\/code><\/a> loads the event which, when clicking on a corresponding link, opens the modal window.<\/p>\n<p>WordPress loads these 3 files for the plugins page:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31077\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-page-loaded-assets.png\" alt=\"Loaded assets in the plugins page\" width=\"2276\" height=\"1542\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-page-loaded-assets.png 2276w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-page-loaded-assets-300x203.png 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-page-loaded-assets-1024x694.png 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-page-loaded-assets-768x520.png 768w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-page-loaded-assets-1536x1041.png 1536w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/plugins-page-loaded-assets-2048x1388.png 2048w\" sizes=\"auto, (max-width: 2276px) 100vw, 2276px\" \/><\/p>\n<p>However, these files are not always loaded in the WordPress admin, only in the plugins page. So, we must add some code to load them in the page where we want to open the modal window. Since the 3 assets are already registered (through file <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/master\/wp-includes\/script-loader.php\"><code>wp-includes\/script-loader.php<\/code><\/a>), we can simply enqueue them for the corresponding page:<\/p>\n<pre><code class=\"language-php\">add_action('admin_enqueue_scripts', 'enqueue_modal_window_assets');\r\n\r\nfunction enqueue_modal_window_assets()\r\n{\r\n  \/\/ Check that we are on the right screen\r\n  if (get_current_screen()-&gt;id == 'my_menu_page') {\r\n    \/\/ Enqueue the assets\r\n    wp_enqueue_style('thickbox');\r\n    wp_enqueue_script('plugin-install');\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>This code loads the assets for a <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/add_menu_page\/\">menu page<\/a> with slug <code>\"my_menu_page\"<\/code>. Enqueuing file <code>plugin-install.js<\/code> also loads <code>thickbox.js<\/code>, so we can skip enqueueing this latter one.<\/p>\n<h2 id=\"printing-link\">Printing the link to open the modal window<\/h2>\n<p>The JavaScript assets introduced above load the modal window in the page, and listen for certain links to be clicked; when that happens, the URL under the link&#8217;s <code>href<\/code> attribute is extracted, and loaded into the modal window&#8217;s <code>iframe<\/code>.<\/p>\n<p>The following code will print a link which, upon clicking, will open the modal window and load within a custom page from the WordPress admin:<\/p>\n<pre><code class=\"language-php\">$url = admin_url('admin.php?page=my_menu_page&amp;TB_iframe=true&amp;width=600&amp;height=550&amp;modal_window=true');\r\nprintf(\r\n  '&lt;a href=\"%s\" class=\"thickbox open-plugin-details-modal\" data-title=\"%s\"&gt;%s&lt;\/a&gt;',\r\n  $url,\r\n  __('View details', 'graphql-api'),\r\n  __('Plugin documentation', 'graphql-api')\r\n);\r\n<\/code><\/pre>\n<p>The link has the following attributes:<\/p>\n<ul>\n<li>Mandatory classnames <code>\"thickbox\"<\/code> and <code>\"open-plugin-details-modal\"<\/code>; without these, when clicked the link would be treated normally, opening the URL in the browser window<\/li>\n<li>URL parameter <code>TB_iframe=true<\/code>; otherwise, the modal window opens with an unsuitable format<\/li>\n<li>URL parameters <code>width<\/code> and <code>height<\/code> are added by the ThickBox library when calculating the <code>iframe<\/code> dimensions based on the viewport&#8217;s size; the WordPress code contains these parameters in advance on the links (for instance, <a href=\"https:\/\/github.com\/WordPress\/WordPress\/blob\/master\/wp-admin\/includes\/class-wp-plugin-install-list-table.php#L609\">here<\/a>) but manually adding them or not makes no difference<\/li>\n<li>Optional attribute <code>data-title<\/code> allows to set the <code>iframe<\/code>&#8216;s <code>title<\/code> attribute; otherwise, <code>\"Plugin details\"<\/code> is used<\/li>\n<\/ul>\n<p>When clicking the link, the JavaScript logic creates a new <code>iframe<\/code> with the URL under the link&#8217;s <code>href<\/code> attribute, minus its parameters <code>TB_iframe<\/code>, <code>width<\/code> and <code>height<\/code>. Then, to let our page know that it is being opened inside the modal window, we further add URL parameter <code>modal_window=true<\/code>.<\/p>\n<h2 id=\"printing-menu-page-or-modal-window\">Printing the menu page or the modal window<\/h2>\n<p>In the WordPress admin, we add pages for our plugin through functions <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/add_menu_page\/\">add_menu_page<\/a> and <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/add_submenu_page\/\">add_submenu_page<\/a>. Registered under its own slug, each page is accessed under <code>admin.php?page=menu_page_slug<\/code>.<\/p>\n<p>In order to display content in the modal window, this has to be registered as a menu page; but then, this page would also be accessible through the admin menu on its own:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31079\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/unwanted-link-in-menu.png\" alt=\"Unwanted link in the menu\" width=\"2186\" height=\"1366\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/unwanted-link-in-menu.png 2186w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/unwanted-link-in-menu-300x187.png 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/unwanted-link-in-menu-1024x640.png 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/unwanted-link-in-menu-768x480.png 768w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/unwanted-link-in-menu-1536x960.png 1536w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/unwanted-link-in-menu-2048x1280.png 2048w\" sizes=\"auto, (max-width: 2186px) 100vw, 2186px\" \/><\/p>\n<p>This is something we want to avoid: a link to open the modal window&#8217;s contents on its own must not be added to the menu.<\/p>\n<p>We use URL parameter <code>modal_window<\/code> added to the link above to provide a solution to this problem: we always register a single page under <code>my_menu_page<\/code>, and then print either the content for the normal page, or the content for the modal window, depending on parameter <code>modal_window<\/code> being present on the URL or not:<\/p>\n<pre><code class=\"language-php\">add_action('admin_menu', 'register_my_custom_menu_page');\r\n\r\nfunction register_my_custom_menu_page() {\r\n  \/\/ If requesting the modal window, print a different output\r\n  $option_function = $_REQUEST['modal_window'] ? 'print_modal_window' : 'print_menu_page';\r\n  add_menu_page( \r\n    __('My Menu Page'),\r\n    'my menu',\r\n    'manage_options',\r\n    'my_menu_page',\r\n    $output_function\r\n  ); \r\n}\r\n\r\n\/**\r\n * Print the contents for the normal menu page\r\n *\/\r\nfunction print_menu_page() {\r\n  \/\/ ...\r\n}\r\n\r\n\/**\r\n * Print the contents displayed within the modal window\r\n *\/\r\nfunction print_modal_window() {\r\n  \/\/ ...\r\n}\r\n<\/code><\/pre>\n<h2 id=\"hiding-admin-menu-inside-modal-window\">Hiding the admin menu inside the modal window<\/h2>\n<p>Because the modal window is being registered as a menu page, it will display the top admin bar:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31075\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/modal-window-with-admin-bar.png\" alt=\"Modal window with top admin bar\" width=\"2186\" height=\"1220\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/modal-window-with-admin-bar.png 2186w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/modal-window-with-admin-bar-300x167.png 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/modal-window-with-admin-bar-1024x571.png 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/modal-window-with-admin-bar-768x429.png 768w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/modal-window-with-admin-bar-1536x857.png 1536w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/modal-window-with-admin-bar-2048x1143.png 2048w\" sizes=\"auto, (max-width: 2186px) 100vw, 2186px\" \/><\/p>\n<p>To hide the admin bar, we create an extra <code>modal-window.css<\/code> file for the modal window:<\/p>\n<pre><code class=\"language-css\">#adminmenumain,\r\n#wpadminbar {\r\n  display: none;\r\n}\r\nhtml.wp-toolbar {\r\n  padding-top: 0;\r\n}\r\n<\/code><\/pre>\n<p>And we load this file whenever the parameter <code>modal_window<\/code> is present in the URL:<\/p>\n<pre><code class=\"language-php\">add_action('admin_enqueue_scripts', 'enqueue_modal_window_css');\r\n\r\nfunction enqueue_modal_window_css()\r\n{\r\n  \/\/ Check that we are on the right screen\r\n  if (get_current_screen()-&gt;id == 'my_menu_page' &amp;&amp; $_REQUEST['modal_window']) {\r\n    wp_enqueue_style('modal-window', plugins_url('css\/modal-window.css', __FILE__));\r\n  }\r\n}\r\n<\/code><\/pre>\n<h2 id=\"adjusting-styles-in-modal-window\">Adjusting the styles inside the modal window<\/h2>\n<p>Finally, when printing the contents of the modal window, they may not be directly suitable for this format. For instance, images are by default not resized to fit within the viewport:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31073\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-not-resized-within-viewport.png\" alt=\"The image is not resized to fit within the viewport\" width=\"2186\" height=\"1220\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-not-resized-within-viewport.png 2186w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-not-resized-within-viewport-300x167.png 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-not-resized-within-viewport-1024x571.png 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-not-resized-within-viewport-768x429.png 768w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-not-resized-within-viewport-1536x857.png 1536w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-not-resized-within-viewport-2048x1143.png 2048w\" sizes=\"auto, (max-width: 2186px) 100vw, 2186px\" \/><\/p>\n<p>To fix this style (and any other that might arise from some particular content), we first wrap the content with a <code>div<\/code> with classname <code>\"modal-window-container\"<\/code>:<\/p>\n<pre><code class=\"language-php\">function print_modal_window()\r\n{\r\n  print('&lt;div class=\"modal-window-container\"&gt;');\r\n  \/\/ ...\r\n  print('&lt;\/div&gt;');\r\n}\r\n<\/code><\/pre>\n<p>And now, we can add the necessary styles in file <code>modal-window.css<\/code> (added above). To make the images fit within the viewport, we add this CSS code:<\/p>\n<pre><code class=\"language-css\">.modal-window-container img {\r\n  max-width: 100%;\r\n  width: auto;\r\n  height: auto;\r\n}\r\n<\/code><\/pre>\n<p>Now, images display properly within the modal window:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31074\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-resized-within-viewport.png\" alt=\"Images fit well within the viewport\" width=\"2186\" height=\"1220\" srcset=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-resized-within-viewport.png 2186w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-resized-within-viewport-300x167.png 300w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-resized-within-viewport-1024x571.png 1024w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-resized-within-viewport-768x429.png 768w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-resized-within-viewport-1536x857.png 1536w, https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/image-resized-within-viewport-2048x1143.png 2048w\" sizes=\"auto, (max-width: 2186px) 100vw, 2186px\" \/><\/p>\n<h2 id=\"conclusion\">End result and conclusion<\/h2>\n<p>Putting all pieces together, we can appreciate the end result:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-31076\" src=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/modal-window.gif\" alt=\"Modal window in the WordPress admin\" width=\"1088\" height=\"648\" \/><\/p>\n<p>Opening modal windows in the WordPress admin can be useful for our themes and plugins, for displaying information to our users. Since this functionality is already shipped within WordPress, it can be achieved very easily, with just a few lines of PHP and CSS code.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When creating a theme or plugin for WordPress which requires users to read some documentation, it is a good idea&#8230;<\/p>\n","protected":false},"author":50,"featured_media":31160,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[51],"tags":[195,11],"class_list":{"0":"post-31072","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-coding","8":"tag-css","9":"tag-wordpress","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v18.1 (Yoast SEO v26.4) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Re-purposing Modal Windows in the WordPress Admin for Your own Needs<\/title>\n<meta name=\"description\" content=\"Opening a modal window in in the WordPress admin by reusing functionality, using PHP and CSS only, no Gutenberg or JavaScript involved\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding Modal Windows in the WordPress Admin Without JavaScript\" \/>\n<meta property=\"og:description\" content=\"When creating a theme or plugin for WordPress which requires users to read some documentation, it is a good idea to display the documentation right within\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/\" \/>\n<meta property=\"og:site_name\" content=\"Design Bombs\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/designbombs\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-23T10:16:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-06-26T08:30:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png\" \/>\n\t<meta property=\"og:image:width\" content=\"722\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Leonardo Losoviz\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@losoviz\" \/>\n<meta name=\"twitter:site\" content=\"@designbombs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Leonardo Losoviz\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/\"},\"author\":{\"name\":\"Leonardo Losoviz\",\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/person\/4259b761dbd3ee01f8c7e2cd9d74df39\"},\"headline\":\"Adding Modal Windows in the WordPress Admin Without JavaScript\",\"datePublished\":\"2020-06-23T10:16:58+00:00\",\"dateModified\":\"2020-06-26T08:30:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/\"},\"wordCount\":1000,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.designbombs.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png\",\"keywords\":[\"css\",\"wordpress\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/\",\"url\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/\",\"name\":\"Re-purposing Modal Windows in the WordPress Admin for Your own Needs\",\"isPartOf\":{\"@id\":\"https:\/\/www.designbombs.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png\",\"datePublished\":\"2020-06-23T10:16:58+00:00\",\"dateModified\":\"2020-06-26T08:30:06+00:00\",\"description\":\"Opening a modal window in in the WordPress admin by reusing functionality, using PHP and CSS only, no Gutenberg or JavaScript involved\",\"breadcrumb\":{\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#primaryimage\",\"url\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png\",\"contentUrl\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png\",\"width\":722,\"height\":300,\"caption\":\"Adding Modal Windows in the WordPress admin without Javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.designbombs.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Coding\",\"item\":\"https:\/\/www.designbombs.com\/category\/coding\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Adding Modal Windows in the WordPress Admin Without JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.designbombs.com\/#website\",\"url\":\"https:\/\/www.designbombs.com\/\",\"name\":\"Design Bombs\",\"description\":\"Droppin&#039; design bombs everyday!\",\"publisher\":{\"@id\":\"https:\/\/www.designbombs.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.designbombs.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.designbombs.com\/#organization\",\"name\":\"DesignBombs\",\"url\":\"https:\/\/www.designbombs.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2019\/04\/db-logo.png\",\"contentUrl\":\"https:\/\/www.designbombs.com\/wp-content\/uploads\/2019\/04\/db-logo.png\",\"width\":219,\"height\":92,\"caption\":\"DesignBombs\"},\"image\":{\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/designbombs\/\",\"https:\/\/x.com\/designbombs\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/person\/4259b761dbd3ee01f8c7e2cd9d74df39\",\"name\":\"Leonardo Losoviz\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.designbombs.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/bb059a4470fd73113804d5dd7430f6a66aaba66ba161798d0fac79b124c74611?s=96&d=https%3A%2F%2Fwww.designbombs.com%2Fwp-content%2Fthemes%2FDesignBombs%2Fimages%2Fgravatar.jpg&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/bb059a4470fd73113804d5dd7430f6a66aaba66ba161798d0fac79b124c74611?s=96&d=https%3A%2F%2Fwww.designbombs.com%2Fwp-content%2Fthemes%2FDesignBombs%2Fimages%2Fgravatar.jpg&r=g\",\"caption\":\"Leonardo Losoviz\"},\"description\":\"Leonardo Losoviz is an open source developer and technical writer, author of GraphQL by PoP, a CMS-agnostic GraphQL server in PHP. Find him on his blog leoloso.com and on Twitter @losoviz.\",\"sameAs\":[\"https:\/\/leoloso.com\",\"https:\/\/x.com\/losoviz\"],\"url\":\"https:\/\/www.designbombs.com\/author\/leo\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Re-purposing Modal Windows in the WordPress Admin for Your own Needs","description":"Opening a modal window in in the WordPress admin by reusing functionality, using PHP and CSS only, no Gutenberg or JavaScript involved","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/","og_locale":"en_US","og_type":"article","og_title":"Adding Modal Windows in the WordPress Admin Without JavaScript","og_description":"When creating a theme or plugin for WordPress which requires users to read some documentation, it is a good idea to display the documentation right within","og_url":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/","og_site_name":"Design Bombs","article_publisher":"https:\/\/www.facebook.com\/designbombs\/","article_published_time":"2020-06-23T10:16:58+00:00","article_modified_time":"2020-06-26T08:30:06+00:00","og_image":[{"width":722,"height":300,"url":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png","type":"image\/png"}],"author":"Leonardo Losoviz","twitter_card":"summary_large_image","twitter_creator":"@losoviz","twitter_site":"@designbombs","twitter_misc":{"Written by":"Leonardo Losoviz","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#article","isPartOf":{"@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/"},"author":{"name":"Leonardo Losoviz","@id":"https:\/\/www.designbombs.com\/#\/schema\/person\/4259b761dbd3ee01f8c7e2cd9d74df39"},"headline":"Adding Modal Windows in the WordPress Admin Without JavaScript","datePublished":"2020-06-23T10:16:58+00:00","dateModified":"2020-06-26T08:30:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/"},"wordCount":1000,"commentCount":2,"publisher":{"@id":"https:\/\/www.designbombs.com\/#organization"},"image":{"@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#primaryimage"},"thumbnailUrl":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png","keywords":["css","wordpress"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/","url":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/","name":"Re-purposing Modal Windows in the WordPress Admin for Your own Needs","isPartOf":{"@id":"https:\/\/www.designbombs.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#primaryimage"},"image":{"@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#primaryimage"},"thumbnailUrl":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png","datePublished":"2020-06-23T10:16:58+00:00","dateModified":"2020-06-26T08:30:06+00:00","description":"Opening a modal window in in the WordPress admin by reusing functionality, using PHP and CSS only, no Gutenberg or JavaScript involved","breadcrumb":{"@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#primaryimage","url":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png","contentUrl":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png","width":722,"height":300,"caption":"Adding Modal Windows in the WordPress admin without Javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/www.designbombs.com\/adding-modal-windows-in-the-wordpress-admin\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.designbombs.com\/"},{"@type":"ListItem","position":2,"name":"Coding","item":"https:\/\/www.designbombs.com\/category\/coding\/"},{"@type":"ListItem","position":3,"name":"Adding Modal Windows in the WordPress Admin Without JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.designbombs.com\/#website","url":"https:\/\/www.designbombs.com\/","name":"Design Bombs","description":"Droppin&#039; design bombs everyday!","publisher":{"@id":"https:\/\/www.designbombs.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.designbombs.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.designbombs.com\/#organization","name":"DesignBombs","url":"https:\/\/www.designbombs.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.designbombs.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2019\/04\/db-logo.png","contentUrl":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2019\/04\/db-logo.png","width":219,"height":92,"caption":"DesignBombs"},"image":{"@id":"https:\/\/www.designbombs.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/designbombs\/","https:\/\/x.com\/designbombs"]},{"@type":"Person","@id":"https:\/\/www.designbombs.com\/#\/schema\/person\/4259b761dbd3ee01f8c7e2cd9d74df39","name":"Leonardo Losoviz","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.designbombs.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/bb059a4470fd73113804d5dd7430f6a66aaba66ba161798d0fac79b124c74611?s=96&d=https%3A%2F%2Fwww.designbombs.com%2Fwp-content%2Fthemes%2FDesignBombs%2Fimages%2Fgravatar.jpg&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/bb059a4470fd73113804d5dd7430f6a66aaba66ba161798d0fac79b124c74611?s=96&d=https%3A%2F%2Fwww.designbombs.com%2Fwp-content%2Fthemes%2FDesignBombs%2Fimages%2Fgravatar.jpg&r=g","caption":"Leonardo Losoviz"},"description":"Leonardo Losoviz is an open source developer and technical writer, author of GraphQL by PoP, a CMS-agnostic GraphQL server in PHP. Find him on his blog leoloso.com and on Twitter @losoviz.","sameAs":["https:\/\/leoloso.com","https:\/\/x.com\/losoviz"],"url":"https:\/\/www.designbombs.com\/author\/leo\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.designbombs.com\/wp-content\/uploads\/2020\/06\/Adding-Modal-Windows-in-the-WordPress-admin.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/posts\/31072","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/users\/50"}],"replies":[{"embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/comments?post=31072"}],"version-history":[{"count":2,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/posts\/31072\/revisions"}],"predecessor-version":[{"id":31162,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/posts\/31072\/revisions\/31162"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/media\/31160"}],"wp:attachment":[{"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/media?parent=31072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/categories?post=31072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.designbombs.com\/wp-json\/wp\/v2\/tags?post=31072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}