/wp-content/themes/my-theme/functions.php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
register_sidebar(array( 'name' => sprintf("%s", __('Admin Screen')), 'id' => 'admin', 'description' => '', 'before_widget' => '<div class="admin widget"><div class="widget-inner">', 'after_widget' => '</div></div>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' )); add_action('wp_dashboard_setup', function () { wp_add_dashboard_widget('wp_dashboard_widget', 'May I help you?', function () { ob_start(); // start buffering output dynamic_sidebar('admin'); $aspectRatio = 9 / 16 * 100; // 56.25% ?> <style type="text/css"> .responsive-video { position: relative; width: 100%; padding-top: <?php echo $aspectRatio; ?>%; } .responsive-video > iframe { position: absolute; top: 0; right: 0; width: 100% !important; height: 100% !important; } #wp_dashboard_widget h2 { background-color: #f2ff9c; } #wp_dashboard_widget h3 { font-weight: bold; } </style> <?php $buffer = ob_get_contents(); // buffered output to variable ob_end_clean(); // end buffering // Keep the Youtube video aspect ratio. if (preg_match('/<iframe[^>]+?(\/www\.youtube\.com\/)[^>]+?>[^<>]*?<\/iframe>/', $buffer, $matches)) { $buffer = str_replace($matches[0], '<div class="responsive-video">'.$matches[0].'</div>', $buffer); } echo $buffer; }); }); |