Dashboard Widgets API

Uses:
function Declaration:
wp_add_dashboard_widget()
function parameters:
wp_add_dashboard_widget($widget_id, $widget_name, $callback, $control_callback=null);
The Action:
add_action();
The Action hook:
wp_dashboard_setup

Example procedure:
open wp function.php and past this steps:
#dashboard setup:
add_action(‘wp_dashboard_setup’,’snd_dashboard_config’);
function snd_dashboard_config(){
wp_add_dashboard_widget(‘snd_dash_id’, __(‘Second Time Configure’,’fifteen’), ‘snd_dash_callback’,’snd_dash_callhandle’);
}

#function callback.
function snd_dash_callback(){
#get save data
if(!$widget_option=get_option(‘dashboard_widget_option’)){
$widget_option=array();
}
#default output
$output=sprintf(‘%s’,__(‘Second Configuration Area ☝’));
#check if save data contains contents
$save_widget_post=isset($widget_option[‘feature_post’])
? $widget_option[‘feature_post’] : false;
#custom content save by controll callback
if($save_widget_post){
$post=get_post($save_widget_post);
if($post){
$content=do_shortcode(html_entity_decode($post->post_content));
$output=”{$post->post_title}{$content}”;
}
}
echo “{$output}”;

}
#function step two
function snd_dash_callhandle(){
#get saved
if(!$widget_option=get_option(‘dashboard_widget_option’)){
$widget_option=array();
}
#process update
if(‘POST’ == $_SERVER[‘REQUEST_METHOD’] && isset($_POST[‘dashboard_widget_option’])){
#mini validation
$widget_option[‘feature_post’]=absint($_POST[‘dashboard_widget_option’][‘feature_post’]);
#save update
update_option(‘dashboard_widget_option’,$widget_option);
}
#set defaults
if(!isset($widget_option[‘feature_post’]))
$widget_option[‘feature_post’]=”;

#process output

echo “Available Pages Title”;

wp_dropdown_pages(array(

‘post_type’=>’page’,
‘name’=>’dashboard_widget_option[feature_post]’,
‘id’=>’feature_post’,
‘show_option_none’=>’-Select-‘,
‘selected’=>$widget_option[‘feature_post’]
));
echo “”;

}

Figure link:

Figure images

Reference link: wp codex

How to show page title in a title bar in your site

  1. Open your Header page and type this code: wp_title(‘|’,true,’right’);
  2. Please open your functions.php file and type this code:

add_action(‘wp_title’,function($tts,$sep){
    global $page,$paged;
    if(is_feed())
        return $tts;
    $tts.=get_bloginfo(‘name’);
    $site_des=get_bloginfo(‘description’,’display’);
    if($site_des && (is_home() || is_front_page()))
    $tts=”$tts $sep $site_des”;
    if($paged >= 2 || $page >= 2)
    $tts=”$tts $sep”.sprintf(__(‘Page %s’,’gprime’),max($paged,$page));
    return $tts;
},10,2);