Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Have a look at the Widgets API.

    Rupam, here’s a simple dashboard widget to get you started. I wrote this so contributors to a client’s site could easily return to the main website…

    <?php
    /**
     * @package Back to Website
     * @version 1.0
     */
    /*
    Plugin Name: Back to Website
    Plugin URI: https://compusolver.com
    Description: Back to website widget.
    Author: Hank Castello
    Version: 1.0
    Author URI: https://compusolver.com
    */
    
    function register_cs_hm_dashboard_widget() {
     	global $wp_meta_boxes;
    
    	wp_add_dashboard_widget(
    		'cs_hm_dashboard_widget',
    		'Back to Website',
    		'cs_hm_dashboard_widget_display'
    	);
    
     	$dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
    
    	$my_widget = array( 'cs_hm_dashboard_widget' => $dashboard['cs_hm_dashboard_widget'] );
     	unset( $dashboard['cs_hm_dashboard_widget'] );
    
     	$sorted_dashboard = array_merge( $my_widget, $dashboard );
     	$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
    }
    
    add_action( 'wp_dashboard_setup', 'register_cs_hm_dashboard_widget' );
    
    function cs_hm_dashboard_widget_display() {
    	?>
            <h2>To return to website:</h2>
    	<p><a href='/'><img src='/wp-content/plugins/cs-hm-widget/home320px.png'></a></p>
    
    	<?php
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Making Custom Widget’ is closed to new replies.