Edits to dashboard widget

Hi
Site is for logged in users only (subscribers)
For some one that ends up on the dasboard I have removed existing dashboard widgets and added on of my own
Everything is working except
I want to include an obvious link back to the site
code I have is
add_action( ‘wp_dashboard_setup’, ‘wporg_add_dashboard_widgets’ );

/**

  • Create the function to output the content of our Dashboard Widget.
    */
    function wporg_dashboard_widget_render() {
    // Display whatever you want to show.
    esc_html_e( “Please click here to go to the website xxxxx” , “wporg” );
    }
    xxxxx is where I want a hyper link to the home page anything I have put in crashes the site

Seems that you are adding wporg_add_dashboard_widgets but the function is wporg_dashboard_widget_render.

Anyway I’m doing it differently in my sites. Here my code:

namespace ISZ\UtilityPlugin;

class Utility {
	public function __construct() {
		add_action('wp_dashboard_setup', [$this, 'remove_dashboard_meta'], PHP_INT_MAX);
		add_action('wp_dashboard_setup', [$this, 'custom_dashboard_widgets'], PHP_INT_MAX);
	}

	public function remove_dashboard_meta() {
		global $wp_meta_boxes;
		$wp_meta_boxes['dashboard'] = [];
		remove_action('welcome_panel', 'wp_welcome_panel');
	}

	public function custom_dashboard_widgets() {
		global $wp_meta_boxes;
		wp_add_dashboard_widget('custom_help_widget', 'Supporto', [$this, 'custom_dashboard_text']);
	}

	public function custom_dashboard_text() {
		echo '<p>Per supporto contattare Simone allo 0000 111 2345 o <a href="mailto:sim[email protected]">[email protected]</a>.';
	}

}

new Utility;
1 Like

Thank you for the quick reply.
I had copied code from https://developer.wordpress.org and had put in functions.php

I now have a utility plugin with your code added and it does just what I wanted with clickable phone, email and link back to the site.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.