如何在WooCommerce产品新增页面持续显示WordPress后台通知
Show Admin Notice Only on WooCommerce Add Product Page
Hey there! Your current code displays the SSL notice on all WordPress admin pages, but we can tweak it to only show up when you're on the WooCommerce add-new-product page specifically. Here's the adjusted solution:
Modified Code Snippet
add_action('admin_notices', 'check_https_on_add_product'); function check_https_on_add_product() { // Grab the current admin screen details $current_screen = get_current_screen(); // Target only the WooCommerce add-new-product page if (isset($current_screen->id) && $current_screen->id === 'product' && isset($_GET['action']) && $_GET['action'] === 'add') { echo '<div class="notice notice-error"><p>You need to enable SSL</p></div>'; } }
Quick Breakdown of Changes:
- Renamed the function to be more descriptive (
check_https_on_add_product) - Added page-specific checks using
get_current_screen():$current_screen->id === 'product'ensures we're on a product-related admin page$_GET['action'] === 'add'narrows it exclusively to the add new product page
- Wrapped the notice text in a
<p>tag to match WordPress admin styling standards
How to Implement:
Add this code to your theme's functions.php file, or use a custom code snippets plugin (like Code Snippets) to avoid losing changes when you update your theme.
内容的提问来源于stack exchange,提问作者user9739520
相关产品推荐
相关产品推荐

