WP Facebook Messenger

FACEBOOK MESSENGER FOR WORDPRESS Fastest way to get connected For any sellers and business owners!

Woocommerce

WOOCOMPOSER Page Builder for WooCommerce WooCommerce Page Builder is The Quickest Way to Create from Product Detail Page to Thank-You Page and Everything in Between.

Facebook Live Chat For Wordpress

FACEBOOK LIVE CHAT FOR WORDPRESS The Very First Step of The 2017 Facebook Marketing Strategy

Yoast SEO

WordPress out of the box is already technically quite a good platform for SEO.

Contact Form 7 Multi-Step

CONTACT FORM 7 MULTI-STEP Featured on our Best WordPress Plugins Adding steps for your complex form The best solution to keep the form clean and simple to your visitors

Friday, December 15, 2017

ADD AND REMOVE THE WIDGET IN THE WORDPRESS WORK


ADD AND REMOVE THE WIDGET IN THE WORDPRESS WORK

When it comes to widgets in WordPress, you probably think of the widgets that appear on your site. However, the widget I mentioned in this article is not for displaying outside the website but as a widget within the admin page, which is located in the Dashboard as shown below.
ADD AND REMOVE THE WIDGET IN THE WORDPRESS WORK
And in this tutorial I will show you how to delete the default widgets as well as create a new widget in the admin page to use it to display some of the information you want.

How to delete the default widget in the admin page

If you are like me, the widgets in the admin page almost do not use it a long time because it is too little information, just as we should delete it to avoid seeing it again.
To do this, we will create a function and hook it into the action hook named wp_dashboard_setup.
01
02
03
04
05
06
07
/**
 * Delete the default widget in the admin page
 */
 function tp_remove_default_admin_widget() {
 }
add_action( 'wp_dashboard_setup', 'tp_remove_default_admin_widget' );

And then in this function we use the remove_meta_box function to delete the widget here. We use this function because these widgets are meta boxes created for page type called dashboard. For example, if you want to remove the WordPress News widget, you have the following:
01
02
03
04
05
06
07
08
09
/**
 * Delete the default widget in the admin page
 */
 function tp_remove_default_admin_widget() {
     remove_meta_box( 'dashboard_primary', 'dashboard', 'side' );
 }
add_action( 'wp_dashboard_setup', 'tp_remove_default_admin_widget' );

Similarly, you can see a list of the default dashboard names here and want to delete which one then copy that into your function.
In case you want to remove the welcome display in the Dashboard, you must use remove_action (), and place the code outside of your function.
01
remove_action( 'welcome_panel', 'wp_welcome_panel' );

How to create a widget in the admin page

Usually when creating a website for a customer, we may need to use the Dashboard to post a reminder notice, or advanced features such as getting the latest news on our site, or updating the price of gold. Something, ... depending on the level of your code.
In this tutorial I will teach you how to create a simple widget and a widget to display the latest posts on your page via RSS.
We first create a separate function and hook it into the action hook named wp_dashboard_setup. And in this function we use the function wp_add_dashboard_widget () to create a new widget.

01
02
03
04
05
06
07
/**
 * Create widget in admin page
 */
 function tp_create_admin_widget_notice() {
    wp_add_dashboard_widget( 'tp_notice',
'Reminder notes','tp_create_admin_widget_notice_callback' );
 }
add_action( 'wp_dashboard_setup',
'tp_create_admin_widget_notice' );

In the above paragraph, we have:

01
wp_add_dashboard_widget( 'tp_notice', 'Reminder notes',
'tp_create_admin_widget_notice_callback' );

Inside:
tp_notice: ID of the widget, the ID must not be the same as the other widgets.
Reminder notes: The title of the widget
tp_create_admin_widget_notice_callback: The name of the function that it will execute in this widget, where you can understand what this function contains which is displayed in the widget whose ID is tp_notice.
Okay, now let's create the function tp_create_admin_widget_notice_callback() that we have declared above to display the content of the generated widget. In this function we temporarily display a simple text.
01
02
03
04
05
06
07
function tp_create_admin_widget_notice_callback() {
    echo '
This is sample content in the tutorial on how to create a
simple widget in the admin page.
';
}

Save and the results we have:
ADD AND REMOVE THE WIDGET IN THE WORDPRESS WORK
If you want to create a widget to display the list of the latest articles on your website or any website, see the instructions in the article Build Your Own WordPress Dashboard Widget for Any RSS Feed.
Since you have full access to the PHP code in this section, you can create your own content here.


The mechanism of use is just that. But hopefully once you know the simplest things, you'll be able to easily find better ways to use widgets in the more useful administration page.

 
loading...