Delete Custom Dashboard Widgets

The built-in dashboard widgets are not marked somehow, you have to use a fixed list: ‘dashboard_right_now’, ‘dashboard_plugins’, ‘dashboard_quick_press’, ‘dashboard_recent_drafts’, ‘dashboard_recent_comments’, ‘dashboard_incoming_links’, ‘dashboard_primary’, ‘dashboard_secondary’ So your code should test if the current widget is in that list and remove the widget, if it isn’t: add_action( ‘wp_dashboard_setup’, ‘t5_remove_custom_dashboard_widgets’, 11 ); function t5_remove_custom_dashboard_widgets() { global $wp_meta_boxes; $builtin = … Read more

Loading shortcode with ajax

You cannot load a file directly like this: $(‘.homepage__slider’).load(‘wp-content/themes/mytheme/slider.php’); Also note that WordPress loads jQuery in noConflict mode, so the $ alias does not work. If you load a file directly none of the WordPress functions will work. You should be using the AJAX API so that everything loads in WordPress context. You would wrap … Read more

Custom wp_nav_menu output (displaying all child elements of top menu element in current branch)

The idea Instead of create a custom walker I thought was easier filter the items using the filter wp_nav_menu_objects hook. This hook is defined in /wp-includes/nav-menu-templates.php and whe is fired, it pass to functions hooking into it an array $sorted_menu_items that contains all the elements of the menu being printed, if the function alter that … Read more

Additional, optional fee on Woocommerce Checkout [closed]

Ok, so this is how i did it. Create a product called Shipping Insurance which is $3, make sure its a hidden product(Catalog Visibility on the right side) Use the following code in your theme’s functions.php file: add_action(‘woocommerce_cart_totals_after_shipping’, ‘wc_shipping_insurance_note_after_cart’); function wc_shipping_insurance_note_after_cart() { global $woocommerce; $product_id = 669; foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) … Read more

How to add a help tab to all admin pages – including plugin pages

This is how you can add help tabs to all admin pages—no matter if there already are any, or not: add_action(‘in_admin_header’, ‘wpse_124979_add_help_tabs’); function wpse_124979_add_help_tabs() { if ($screen = get_current_screen()) { $help_tabs = $screen->get_help_tabs(); $screen->remove_help_tabs(); $screen->add_help_tab(array( ‘id’ => ‘my_help_tab’, ‘title’ => ‘My Help’, ‘content’ => ‘<p>My help content…</p>’, )); if (count($help_tabs)) foreach ($help_tabs as $help_tab) $screen->add_help_tab($help_tab); … Read more

How to parse nested shortcodes?

There’s a solution for that, actually. The shortcode you are using has the variable $content, whithout the filter do_shortcode, like this: do_shortcode($content) Open the file where there are the shortcodes and change $content for do_shortcode($content). It will work.

How to add meta box to plugin admin page?

add_meta_boxes is for adding meta boxes to post types. What you’re looking for is the Settings API. In your add_menu_page function you are calling a function named test_plugin_admin_options. This function will hold the content of your options page. You will also need to register your settings with register_setting(). //add menu page add_action(‘admin_menu’, ‘test’); function test(){ … Read more

To remove plugin notices for non-admin users

The simplest way would be to hide the notifications via CSS, see below: function hide_update_msg_non_admins(){ if (!current_user_can( ‘manage_options’ )) { // non-admin users echo ‘<style>#setting-error-tgmpa>.updated settings-error notice is-dismissible, .update-nag, .updated { display: none; }</style>’; } } add_action( ‘admin_head’, ‘hide_update_msg_non_admins’); A more detailed answer can be found here.