WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I will start by warning you that my programming skill is limited.

I need to create a dashboard widget that will display in the WP dashboard for the users with the user_id=21.

So far I have tried the following code, but it isn't working:

function my_catdb() {
echo '<a href="http://xxxxxxxxxxx.org/?frm_display=single-catproblem">View the Problem Problem Database.</a>';
 * add Dashboard Widget via function wp_add_dashboard_widget()
function my_catdb_setup() {
    wp_add_dashboard_widget( 'my_catdb', __( 'Cataloging Problem Database' ), 'my_catdb'         );
 * use hook, to integrate new widget
$user_id = get_current_user_id();
if ( is_user_logged_in() ) {  
if ( $user_id = 21 ) {
add_action('wp_dashboard_setup', 'my_wp_dashboard_setup');

Any help is appreciated. Thanks

share|improve this question
In what way is it not working? Do you have debugging information? – s_ha_dum Jan 10 '13 at 17:25

You have to wait for wp_loaded to use get_current_user_id().


add_action( 'wp_loaded', 'wpse_80061_load_dashboard_widget' );

function wpse_80061_load_dashboard_widget()
    if ( 1 === get_current_user_id() )
        add_action( 'wp_dashboard_setup', 'wpse_80061_add_dashboard_widget' );
        // your function:
        // add_action( 'wp_dashboard_setup', 'my_catdb_setup' );

function wpse_80061_add_dashboard_widget()

function wpse_80061_render_dashboard_widget()
    echo 'hey!';

For a dashboard widget with more details see my plugin T5 Table size dashboard widget.

share|improve this answer
I appreciate you taking the time to help, but I'm not sure what to replace to make it work with my existing code. – Sayid Jan 10 '13 at 16:41
@Sayid See my update. I have inserted a comment where you can call your function. – toscho Jan 10 '13 at 16:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.