我正在尝试向我的WordPress插件添加通知和错误消息。使用admin_notices钩子,我的代码看起来像这样:
<?php
//Define notifications
function customer_admin_notice($message_type, $customer_nr = "") {
if ($message_type === 'customer_update_success') {
?>
<div class="notice notice-success is-dismissible">
<p><?php echo 'Customer updated successfully.'; ?></p>
</div>
<?php
} else if ($message_type === 'customer_new_success') {
?>
<div class="notice notice-success is-dismissible">
<p><?php echo 'Customer added successfully.'; ?></p>
</div>
<?php
} else if ($message_type === 'customer_delete_success') {
?>
<div class="notice notice-success is-dismissible">
<p><?php echo 'Customer with number ' . $customer_nr . ' has been deleted.'; ?></p>
</div>
<?php
} else if ($message_type === 'customer_delete_error') {
?>
<div class="notice notice-error is-dismissible">
<p><?php echo 'No customer with number ' . $customer_nr . ' was found.'; ?></p>
</div>
<?php
}
}
add_action('admin_notices', 'customer_admin_notice');
?>
通知会打印出来,但看起来像这样:Notification shows full width and behind side panel
我还注意到,通知get直接附加在body标签下,不像其他附加到wpbody-content的通知:DOM
有没有人知道为什么通知没有正确显示?
1条答案
按热度按时间xxe27gdn1#
似乎admin_notices钩子在呈现wpbody-content容器之前被触发。下面是更新后的代码,应该可以正常工作:
它可能会帮助你解决这个问题!