我想在我的自定义仪表板小部件中添加一个类名,但我在搜索codex时找不到这样做的方法。现在我的小部件上唯一的类名是postbox
(这是在“/wp admin/includes/template.php”中添加的),但我想添加更多。我该怎么做?
add_action(\'wp_dashboard_setup\', function () {
wp_add_dashboard_widget(\'widget2\',\'Graph\',\'widget_2\');
});
function widget_2($post){
var_dump($post); /* string \'\' (length=0) */
?>
<div id="graph-points-by-time" class="graph-points-by-time"></div>
<br class="clear">
<div id="graph-legend" class="graph-legend height-auto"></div>
<?php
}
最合适的回答,由SO网友:cybmeta 整理而成
你可以使用postbox_classes
filter 具体如下:
add_filter( \'postbox_classes_dashboard_widget2\', function ( $classes ) {
// $classes is an array; add your custom classes to the array
$classes[] = \'my-class\';
return $classes;
} );